Skip to content

Commit 691e774

Browse files
authored
refactor!: make base parameter compulsory in math/base/special/floorsd
BREAKING CHANGE: 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 ``` PR-URL: #2617 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent dcb1b32 commit 691e774

File tree

8 files changed

+48
-76
lines changed

8 files changed

+48
-76
lines changed

lib/node_modules/@stdlib/math/base/special/floorsd/README.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,21 @@ limitations under the License.
3030
var floorsd = require( '@stdlib/math/base/special/floorsd' );
3131
```
3232

33-
#### floorsd( x, n\[, b] )
33+
#### floorsd( x, n, b )
3434

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

3737
```javascript
38-
var v = floorsd( 3.141592653589793, 5 );
38+
var v = floorsd( 3.141592653589793, 5, 10 );
3939
// returns 3.1415
4040

41-
v = floorsd( 3.141592653589793, 1 );
41+
v = floorsd( 3.141592653589793, 1, 10 );
4242
// returns 3.0
4343

44-
v = floorsd( 12368.0, 2 );
44+
v = floorsd( 12368.0, 2, 10 );
4545
// returns 12000.0
46-
```
47-
48-
The default base is `10` (decimal). To round using a different base, provide a third argument.
4946

50-
```javascript
51-
var v = floorsd( 0.0313, 2, 2 );
47+
v = floorsd( 0.0313, 2, 2 );
5248
// returns 0.03125
5349
```
5450

@@ -78,7 +74,7 @@ var i;
7874

7975
for ( i = 0; i < 100; i++ ) {
8076
x = (randu()*10000.0) - 5000.0;
81-
y = floorsd( x, 5 );
77+
y = floorsd( x, 5, 10 );
8278
console.log( 'x: %d. Rounded: %d.', x, y );
8379
}
8480
```

lib/node_modules/@stdlib/math/base/special/floorsd/docs/repl.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

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

@@ -11,8 +11,8 @@
1111
n: integer
1212
Number of significant figures. Must be greater than 0.
1313

14-
b: integer (optional)
15-
Base. Must be greater than 0. Default: 10.
14+
b: integer
15+
Base. Must be greater than 0.
1616

1717
Returns
1818
-------
@@ -21,11 +21,11 @@
2121

2222
Examples
2323
--------
24-
> var y = {{alias}}( 3.14159, 5 )
24+
> var y = {{alias}}( 3.14159, 5, 10 )
2525
3.1415
26-
> y = {{alias}}( 3.14159, 1 )
26+
> y = {{alias}}( 3.14159, 1, 10 )
2727
3.0
28-
> y = {{alias}}( 12368.0, 2 )
28+
> y = {{alias}}( 12368.0, 2, 10 )
2929
12000.0
3030
> y = {{alias}}( 0.0313, 2, 2 )
3131
0.03125

lib/node_modules/@stdlib/math/base/special/floorsd/docs/types/index.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@
2323
*
2424
* @param x - input value
2525
* @param n - number of significant figures
26-
* @param b - base (default: 10)
26+
* @param b - base
2727
* @returns rounded value
2828
*
2929
* @example
30-
* var v = floorsd( 3.141592653589793, 5 );
30+
* var v = floorsd( 3.141592653589793, 5, 10 );
3131
* // returns 3.1415
3232
*
3333
* @example
34-
* var v = floorsd( 3.141592653589793, 1 );
34+
* var v = floorsd( 3.141592653589793, 1, 10 );
3535
* // returns 3.0
3636
*
3737
* @example
38-
* var v = floorsd( 12368.0, 2 );
38+
* var v = floorsd( 12368.0, 2, 10 );
3939
* // returns 12000.0
4040
*
4141
* @example
4242
* var v = floorsd( 0.0313, 2, 2 );
4343
* // returns 0.03125
4444
*/
45-
declare function floorsd( x: number, n: number, b?: number ): number;
45+
declare function floorsd( x: number, n: number, b: number ): number;
4646

4747

4848
// EXPORTS //

lib/node_modules/@stdlib/math/base/special/floorsd/docs/types/test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import floorsd = require( './index' );
2424
// The function returns a number...
2525
{
2626
floorsd( 3.141592653589793, 4, 10 ); // $ExpectType number
27-
floorsd( 3.141592653589793, 4 ); // $ExpectType number
2827
}
2928

3029
// The compiler throws an error if the function is provided values other than numbers...

lib/node_modules/@stdlib/math/base/special/floorsd/examples/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ var i;
2727

2828
for ( i = 0; i < 100; i++ ) {
2929
x = (randu()*10000.0) - 5000.0;
30-
y = floorsd( x, 5 );
30+
y = floorsd( x, 5, 10 );
3131
console.log( 'x: %d. Rounded: %d.', x, y );
3232
}

lib/node_modules/@stdlib/math/base/special/floorsd/lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
* @example
2727
* var floorsd = require( '@stdlib/math/base/special/floorsd' );
2828
*
29-
* var v = floorsd( 3.141592653589793, 5 );
29+
* var v = floorsd( 3.141592653589793, 5, 10 );
3030
* // returns 3.1415
3131
*
32-
* v = floorsd( 3.141592653589793, 1 );
32+
* v = floorsd( 3.141592653589793, 1, 10 );
3333
* // returns 3.0
3434
*
35-
* v = floorsd( 12368.0, 2 );
35+
* v = floorsd( 12368.0, 2, 10 );
3636
* // returns 12000.0
3737
*
3838
* v = floorsd( 0.0313, 2, 2 );

lib/node_modules/@stdlib/math/base/special/floorsd/lib/main.js

+14-20
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,26 @@ var exponent = require( '@stdlib/number/float64/base/exponent' );
3737
*
3838
* @param {number} x - input value
3939
* @param {PositiveInteger} n - number of significant figures
40-
* @param {PositiveInteger} [b=10] - base
40+
* @param {PositiveInteger} b - base
4141
* @returns {number} rounded value
4242
*
4343
* @example
44-
* var v = floorsd( 3.141592653589793, 5 );
44+
* var v = floorsd( 3.141592653589793, 5, 10 );
4545
* // returns 3.1415
4646
*
4747
* @example
48-
* var v = floorsd( 3.141592653589793, 1 );
48+
* var v = floorsd( 3.141592653589793, 1, 10 );
4949
* // returns 3.0
5050
*
5151
* @example
52-
* var v = floorsd( 12368.0, 2 );
52+
* var v = floorsd( 12368.0, 2, 10 );
5353
* // returns 12000.0
5454
*
5555
* @example
5656
* var v = floorsd( 0.0313, 2, 2 );
5757
* // returns 0.03125
5858
*/
5959
function floorsd( x, n, b ) {
60-
var base;
6160
var exp;
6261
var s;
6362
var y;
@@ -69,32 +68,27 @@ function floorsd( x, n, b ) {
6968
) {
7069
return NaN;
7170
}
72-
if ( arguments.length > 2 ) {
73-
if (
74-
isnan( b ) ||
75-
b <= 0 ||
76-
isInfinite( b )
77-
) {
78-
return NaN;
79-
}
80-
base = b;
81-
} else {
82-
base = 10;
71+
if (
72+
isnan( b ) ||
73+
b <= 0 ||
74+
isInfinite( b )
75+
) {
76+
return NaN;
8377
}
8478
if ( isInfinite( x ) || x === 0.0 ) {
8579
return x;
8680
}
87-
if ( base === 10 ) {
81+
if ( b === 10 ) {
8882
exp = log10( abs( x ) );
8983
}
90-
else if ( base === 2 ) {
84+
else if ( b === 2 ) {
9185
exp = exponent( abs( x ) );
9286
}
9387
else {
94-
exp = ln( abs(x) ) / ln( base );
88+
exp = ln( abs(x) ) / ln( b );
9589
}
9690
exp = floor( exp - n + 1.0 );
97-
s = pow( base, abs( exp ) );
91+
s = pow( b, abs( exp ) );
9892

9993
// Check for overflow:
10094
if ( isInfinite( s ) ) {

lib/node_modules/@stdlib/math/base/special/floorsd/test/test.js

+13-30
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ tape( 'main export is a function', function test( t ) {
4141
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
4242
var v;
4343

44-
v = floorsd( NaN, 2 );
44+
v = floorsd( NaN, 2, 10 );
4545
t.strictEqual( isnan( v ), true, 'returns NaN' );
4646

47-
v = floorsd( 12368.0, NaN );
47+
v = floorsd( 12368.0, NaN, 10 );
4848
t.strictEqual( isnan( v ), true, 'returns NaN' );
4949

50-
v = floorsd( NaN, NaN );
50+
v = floorsd( NaN, NaN, 10 );
5151
t.strictEqual( isnan( v ), true, 'returns NaN' );
5252

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

71-
v = floorsd( PI, PINF );
71+
v = floorsd( PI, PINF, 10 );
7272
t.strictEqual( isnan( v ), true, 'returns NaN' );
7373

74-
v = floorsd( PI, NINF );
74+
v = floorsd( PI, NINF, 10 );
7575
t.strictEqual( isnan( v ), true, 'returns NaN' );
7676

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

83-
v = floorsd( PI, 0 );
83+
v = floorsd( PI, 0, 10 );
8484
t.strictEqual( isnan( v ), true, 'returns NaN' );
8585

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

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

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

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

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

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

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

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

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

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

149149
t.end();
150150
});
151151

152-
tape( 'the function supports rounding a numeric value with a specified number of significant figures', function test( t ) {
153-
t.strictEqual( floorsd( PI, 1 ), 3.0, 'returns expected value' );
154-
t.strictEqual( floorsd( -PI, 1 ), -4.0, 'returns expected value' );
155-
t.strictEqual( floorsd( PI, 2 ), 3.1, 'returns expected value' );
156-
t.strictEqual( floorsd( -PI, 2 ), -3.2, 'returns expected value' );
157-
t.strictEqual( floorsd( PI, 3 ), 3.14, 'returns expected value' );
158-
t.strictEqual( floorsd( -PI, 3 ), -3.15, 'returns expected value' );
159-
t.strictEqual( floorsd( PI, 5 ), 3.1415, 'returns expected value' );
160-
t.strictEqual( floorsd( -PI, 5 ), -3.1416, 'returns expected value' );
161-
t.strictEqual( floorsd( 0.0, 2 ), 0.0, 'returns expected value' );
162-
t.strictEqual( floorsd( 12368.0, 3 ), 12300.0, 'returns expected value' );
163-
t.strictEqual( floorsd( -12368.0, 3 ), -12400.0, 'returns expected value' );
164-
t.strictEqual( floorsd( 12368.0, 2 ), 12000.0, 'returns expected value' );
165-
t.strictEqual( floorsd( -12368.0, 2 ), -13000.0, 'returns expected value' );
166-
t.end();
167-
});
168-
169152
tape( 'the function supports rounding a numeric value with a specified number of significant figures (base 10)', function test( t ) {
170153
t.strictEqual( floorsd( PI, 1, 10 ), 3.0, 'returns expected value' );
171154
t.strictEqual( floorsd( -PI, 1, 10 ), -4.0, 'returns expected value' );

0 commit comments

Comments
 (0)