Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jul 18, 2024
1 parent 0f63aef commit bd3230c
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 76 deletions.
47 changes: 47 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,29 @@ This release closes the following issue:

<!-- /.features -->

<section class="breaking-changes">

##### BREAKING CHANGES

- [`691e774`](https://github.com/stdlib-js/stdlib/commit/691e774930ab3d983998e53ad16dbf4bd5eb0c76): make base parameter compulsory in `math/base/special/floorsd`
- [`691e774`](https://github.com/stdlib-js/stdlib/commit/691e774930ab3d983998e53ad16dbf4bd5eb0c76): The base parameter must now be provided explicitly.

- Previously, the base parameter had a default value of 10. Now it has to be supplied explicitly.
Before:
```
var v = floorsd( 3.141592653589793, 5 );
// returns 3.1415
```
After:
```
var v = floorsd( 3.141592653589793, 5, 10 );
// returns 3.1415
```

</section>

<!-- /.breaking-changes -->

</details>

</section>
Expand Down Expand Up @@ -5184,6 +5207,29 @@ This release closes the following issue:

<!-- /.packages -->

<section class="breaking-changes">

### BREAKING CHANGES

- [`691e774`](https://github.com/stdlib-js/stdlib/commit/691e774930ab3d983998e53ad16dbf4bd5eb0c76): make base parameter compulsory in `math/base/special/floorsd`
- [`691e774`](https://github.com/stdlib-js/stdlib/commit/691e774930ab3d983998e53ad16dbf4bd5eb0c76): The base parameter must now be provided explicitly.

- Previously, the base parameter had a default value of 10. Now it has to be supplied explicitly.
Before:
```
var v = floorsd( 3.141592653589793, 5 );
// returns 3.1415
```
After:
```
var v = floorsd( 3.141592653589793, 5, 10 );
// returns 3.1415
```

</section>

<!-- /.breaking-changes -->

<section class="issues">

### Closed Issues
Expand Down Expand Up @@ -5242,6 +5288,7 @@ A total of 29 people contributed to this release. Thank you to the following con

<details>

- [`691e774`](https://github.com/stdlib-js/stdlib/commit/691e774930ab3d983998e53ad16dbf4bd5eb0c76) - **refactor:** make base parameter compulsory in `math/base/special/floorsd` [(##2617)](#2617) _(by Gunj Joshi)_
- [`dcb1b32`](https://github.com/stdlib-js/stdlib/commit/dcb1b32226e846c8c5219507bc30dce3bbcf19d2) - **feat:** add C implementation for `math/base/special/floorb` [(##2620)](#2620) _(by Gunj Joshi)_
- [`cc98b20`](https://github.com/stdlib-js/stdlib/commit/cc98b20ab91590c526896d547e447f107fc714aa) - **feat:** add C implementation for `math/base/special/factorial` [(##2618)](#2618 ) _(by Gunj Joshi)_
- [`1f99cd7`](https://github.com/stdlib-js/stdlib/commit/1f99cd7f06bd5e3027f29c6d816ea39e8624cab1) - **feat:** add C implementation for `math/base/special/floor10` [(##2619)](#2619) _(by Gunj Joshi)_
Expand Down
16 changes: 6 additions & 10 deletions base/special/floorsd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,21 @@ limitations under the License.
var floorsd = require( '@stdlib/math/base/special/floorsd' );
```

#### floorsd( x, n\[, b] )
#### floorsd( x, n, b )

Rounds a `numeric` value to the nearest `number` toward negative infinity with `n` significant figures.

```javascript
var v = floorsd( 3.141592653589793, 5 );
var v = floorsd( 3.141592653589793, 5, 10 );
// returns 3.1415

v = floorsd( 3.141592653589793, 1 );
v = floorsd( 3.141592653589793, 1, 10 );
// returns 3.0

v = floorsd( 12368.0, 2 );
v = floorsd( 12368.0, 2, 10 );
// returns 12000.0
```

The default base is `10` (decimal). To round using a different base, provide a third argument.

```javascript
var v = floorsd( 0.0313, 2, 2 );
v = floorsd( 0.0313, 2, 2 );
// returns 0.03125
```

Expand Down Expand Up @@ -78,7 +74,7 @@ var i;

for ( i = 0; i < 100; i++ ) {
x = (randu()*10000.0) - 5000.0;
y = floorsd( x, 5 );
y = floorsd( x, 5, 10 );
console.log( 'x: %d. Rounded: %d.', x, y );
}
```
Expand Down
12 changes: 6 additions & 6 deletions base/special/floorsd/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{{alias}}( x, n[, b] )
{{alias}}( x, n, b )
Rounds a numeric value to the nearest number toward negative infinity with
`n` significant figures.

Expand All @@ -11,8 +11,8 @@
n: integer
Number of significant figures. Must be greater than 0.

b: integer (optional)
Base. Must be greater than 0. Default: 10.
b: integer
Base. Must be greater than 0.

Returns
-------
Expand All @@ -21,11 +21,11 @@

Examples
--------
> var y = {{alias}}( 3.14159, 5 )
> var y = {{alias}}( 3.14159, 5, 10 )
3.1415
> y = {{alias}}( 3.14159, 1 )
> y = {{alias}}( 3.14159, 1, 10 )
3.0
> y = {{alias}}( 12368.0, 2 )
> y = {{alias}}( 12368.0, 2, 10 )
12000.0
> y = {{alias}}( 0.0313, 2, 2 )
0.03125
Expand Down
10 changes: 5 additions & 5 deletions base/special/floorsd/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@
*
* @param x - input value
* @param n - number of significant figures
* @param b - base (default: 10)
* @param b - base
* @returns rounded value
*
* @example
* var v = floorsd( 3.141592653589793, 5 );
* var v = floorsd( 3.141592653589793, 5, 10 );
* // returns 3.1415
*
* @example
* var v = floorsd( 3.141592653589793, 1 );
* var v = floorsd( 3.141592653589793, 1, 10 );
* // returns 3.0
*
* @example
* var v = floorsd( 12368.0, 2 );
* var v = floorsd( 12368.0, 2, 10 );
* // returns 12000.0
*
* @example
* var v = floorsd( 0.0313, 2, 2 );
* // returns 0.03125
*/
declare function floorsd( x: number, n: number, b?: number ): number;
declare function floorsd( x: number, n: number, b: number ): number;


// EXPORTS //
Expand Down
1 change: 0 additions & 1 deletion base/special/floorsd/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import floorsd = require( './index' );
// The function returns a number...
{
floorsd( 3.141592653589793, 4, 10 ); // $ExpectType number
floorsd( 3.141592653589793, 4 ); // $ExpectType number
}

// The compiler throws an error if the function is provided values other than numbers...
Expand Down
2 changes: 1 addition & 1 deletion base/special/floorsd/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ var i;

for ( i = 0; i < 100; i++ ) {
x = (randu()*10000.0) - 5000.0;
y = floorsd( x, 5 );
y = floorsd( x, 5, 10 );
console.log( 'x: %d. Rounded: %d.', x, y );
}
6 changes: 3 additions & 3 deletions base/special/floorsd/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
* @example
* var floorsd = require( '@stdlib/math/base/special/floorsd' );
*
* var v = floorsd( 3.141592653589793, 5 );
* var v = floorsd( 3.141592653589793, 5, 10 );
* // returns 3.1415
*
* v = floorsd( 3.141592653589793, 1 );
* v = floorsd( 3.141592653589793, 1, 10 );
* // returns 3.0
*
* v = floorsd( 12368.0, 2 );
* v = floorsd( 12368.0, 2, 10 );
* // returns 12000.0
*
* v = floorsd( 0.0313, 2, 2 );
Expand Down
34 changes: 14 additions & 20 deletions base/special/floorsd/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,26 @@ var exponent = require( '@stdlib/number/float64/base/exponent' );
*
* @param {number} x - input value
* @param {PositiveInteger} n - number of significant figures
* @param {PositiveInteger} [b=10] - base
* @param {PositiveInteger} b - base
* @returns {number} rounded value
*
* @example
* var v = floorsd( 3.141592653589793, 5 );
* var v = floorsd( 3.141592653589793, 5, 10 );
* // returns 3.1415
*
* @example
* var v = floorsd( 3.141592653589793, 1 );
* var v = floorsd( 3.141592653589793, 1, 10 );
* // returns 3.0
*
* @example
* var v = floorsd( 12368.0, 2 );
* var v = floorsd( 12368.0, 2, 10 );
* // returns 12000.0
*
* @example
* var v = floorsd( 0.0313, 2, 2 );
* // returns 0.03125
*/
function floorsd( x, n, b ) {
var base;
var exp;
var s;
var y;
Expand All @@ -69,32 +68,27 @@ function floorsd( x, n, b ) {
) {
return NaN;
}
if ( arguments.length > 2 ) {
if (
isnan( b ) ||
b <= 0 ||
isInfinite( b )
) {
return NaN;
}
base = b;
} else {
base = 10;
if (
isnan( b ) ||
b <= 0 ||
isInfinite( b )
) {
return NaN;
}
if ( isInfinite( x ) || x === 0.0 ) {
return x;
}
if ( base === 10 ) {
if ( b === 10 ) {
exp = log10( abs( x ) );
}
else if ( base === 2 ) {
else if ( b === 2 ) {
exp = exponent( abs( x ) );
}
else {
exp = ln( abs(x) ) / ln( base );
exp = ln( abs(x) ) / ln( b );
}
exp = floor( exp - n + 1.0 );
s = pow( base, abs( exp ) );
s = pow( b, abs( exp ) );

// Check for overflow:
if ( isInfinite( s ) ) {
Expand Down
43 changes: 13 additions & 30 deletions base/special/floorsd/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ tape( 'main export is a function', function test( t ) {
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var v;

v = floorsd( NaN, 2 );
v = floorsd( NaN, 2, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );

v = floorsd( 12368.0, NaN );
v = floorsd( 12368.0, NaN, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );

v = floorsd( NaN, NaN );
v = floorsd( NaN, NaN, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );

v = floorsd( NaN, NaN, 10 );
Expand All @@ -68,10 +68,10 @@ tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
tape( 'the function returns `NaN` if provided `n = +-infinity`', function test( t ) {
var v;

v = floorsd( PI, PINF );
v = floorsd( PI, PINF, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );

v = floorsd( PI, NINF );
v = floorsd( PI, NINF, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );

t.end();
Expand All @@ -80,10 +80,10 @@ tape( 'the function returns `NaN` if provided `n = +-infinity`', function test(
tape( 'the function returns `NaN` if provided `n < 1`', function test( t ) {
var v;

v = floorsd( PI, 0 );
v = floorsd( PI, 0, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );

v = floorsd( PI, -1 );
v = floorsd( PI, -1, 10 );
t.strictEqual( isnan( v ), true, 'returns NaN' );

t.end();
Expand Down Expand Up @@ -114,24 +114,24 @@ tape( 'the function returns `NaN` if provided `b <= 0`', function test( t ) {
});

tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) {
var v = floorsd( PINF, 5 );
var v = floorsd( PINF, 5, 10 );
t.strictEqual( v, PINF, 'returns +infinity' );
t.end();
});

tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) {
var v = floorsd( NINF, 3 );
var v = floorsd( NINF, 3, 10 );
t.strictEqual( v, NINF, 'returns -infinity' );
t.end();
});

tape( 'the function returns `-0` if provided `-0`', function test( t ) {
var v;

v = floorsd( -0.0, 1 );
v = floorsd( -0.0, 1, 10 );
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );

v = floorsd( -0.0, 2 );
v = floorsd( -0.0, 2, 10 );
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );

t.end();
Expand All @@ -140,32 +140,15 @@ tape( 'the function returns `-0` if provided `-0`', function test( t ) {
tape( 'the function returns `+0` if provided `+0`', function test( t ) {
var v;

v = floorsd( 0.0, 1 );
v = floorsd( 0.0, 1, 10 );
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );

v = floorsd( +0.0, 2 );
v = floorsd( +0.0, 2, 10 );
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );

t.end();
});

tape( 'the function supports rounding a numeric value with a specified number of significant figures', function test( t ) {
t.strictEqual( floorsd( PI, 1 ), 3.0, 'returns expected value' );
t.strictEqual( floorsd( -PI, 1 ), -4.0, 'returns expected value' );
t.strictEqual( floorsd( PI, 2 ), 3.1, 'returns expected value' );
t.strictEqual( floorsd( -PI, 2 ), -3.2, 'returns expected value' );
t.strictEqual( floorsd( PI, 3 ), 3.14, 'returns expected value' );
t.strictEqual( floorsd( -PI, 3 ), -3.15, 'returns expected value' );
t.strictEqual( floorsd( PI, 5 ), 3.1415, 'returns expected value' );
t.strictEqual( floorsd( -PI, 5 ), -3.1416, 'returns expected value' );
t.strictEqual( floorsd( 0.0, 2 ), 0.0, 'returns expected value' );
t.strictEqual( floorsd( 12368.0, 3 ), 12300.0, 'returns expected value' );
t.strictEqual( floorsd( -12368.0, 3 ), -12400.0, 'returns expected value' );
t.strictEqual( floorsd( 12368.0, 2 ), 12000.0, 'returns expected value' );
t.strictEqual( floorsd( -12368.0, 2 ), -13000.0, 'returns expected value' );
t.end();
});

tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 10)', function test( t ) {
t.strictEqual( floorsd( PI, 1, 10 ), 3.0, 'returns expected value' );
t.strictEqual( floorsd( -PI, 1, 10 ), -4.0, 'returns expected value' );
Expand Down

0 comments on commit bd3230c

Please sign in to comment.