Skip to content

Commit 5cddadf

Browse files
committed
chore: clean-up
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent fb07e54 commit 5cddadf

File tree

9 files changed

+72
-62
lines changed

9 files changed

+72
-62
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ v = roundnf( 12368.0, 3 );
6363
// returns 0.30000000000000004
6464

6565
// Should round to 0.3...
66-
var v = roundnf( x, -16 );
66+
var v = roundnf( x, -7 );
6767
// returns 0.30000001192092896
6868
```
6969

lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ bench( pkg, function benchmark( b ) {
3939
x = uniform( 100, -100.0, 100.0, {
4040
'dtype': 'float32'
4141
});
42-
n = discreteUniform( 100, -5, 0 );
42+
n = discreteUniform( 100, -5, 0, {
43+
'dtype': 'int32'
44+
});
4345

4446
b.tic();
4547
for ( i = 0; i < b.iterations; i++ ) {

lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/benchmark.native.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
26-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2727
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var format = require( '@stdlib/string/format' );
2930
var pkg = require( './../package.json' ).name;
3031

3132

@@ -39,17 +40,22 @@ var opts = {
3940

4041
// MAIN //
4142

42-
bench( pkg+'::native', opts, function benchmark( b ) {
43+
bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
4344
var x;
4445
var n;
4546
var y;
4647
var i;
4748

49+
x = uniform( 100, -100.0, 100.0, {
50+
'dtype': 'float32'
51+
});
52+
n = discreteUniform( 100, -5, 0, {
53+
'dtype': 'int32'
54+
});
55+
4856
b.tic();
4957
for ( i = 0; i < b.iterations; i++ ) {
50-
x = ( randu() * 100.0 ) - 50.0;
51-
n = discreteUniform( -5, 0 );
52-
y = roundnf( x, n );
58+
y = roundnf( x[ i%x.length ], n[ i%n.length ] );
5359
if ( isnanf( y ) ) {
5460
b.fail( 'should not return NaN' );
5561
}

lib/node_modules/@stdlib/math/base/special/roundnf/benchmark/c/native/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ static int random_discrete_uniform( const int min, const int max ) {
103103
* @return elapsed time in seconds
104104
*/
105105
static double benchmark( void ) {
106+
double elapsed;
106107
float x[ 100 ];
107108
int n[ 100 ];
108-
double elapsed;
109109
double t;
110110
float y;
111111
int i;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
12
{{alias}}( x, n )
2-
Rounds a single-precision floating-point number to the nearest multiple
3-
of `10^n`.
3+
Rounds a single-precision floating-point number to the nearest multiple of
4+
`10^n`.
45

56
Parameters
67
----------

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ var MIN_EXP_SUBNORMAL = require( '@stdlib/constants/float32/min-base10-exponent-
3636

3737
var MAX_INT = MAX_SAFE_INTEGER + 1;
3838
var HUGE = f32( 1.0e+38 );
39+
var ZERO = f32( 0.0 );
40+
var TEN = f32( 10.0 );
3941

4042

4143
// MAIN //
@@ -61,7 +63,7 @@ var HUGE = f32( 1.0e+38 );
6163
*
6264
* <!-- <note> -->
6365
*
64-
* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) is \\(0.30000001192092896\\) and not \\(0.3\\). While possibly unexpected, this is not a bug. The behavior stems from the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\mathrm{roundf}\\).
66+
* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-7)\\) is \\(0.30000001192092896\\) and not \\(0.3\\). While possibly unexpected, this is not a bug. The behavior stems from the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\mathrm{roundf}\\).
6567
*
6668
* <!-- </note> -->
6769
*
@@ -127,7 +129,7 @@ function roundnf( x, n ) {
127129
isInfinitef( x ) ||
128130

129131
// Handle +-0...
130-
x === 0.0 ||
132+
x === ZERO ||
131133

132134
// If `n` exceeds the maximum number of feasible decimal places (such as with subnormal numbers), nothing to round...
133135
n < MIN_EXP_SUBNORMAL ||
@@ -139,18 +141,18 @@ function roundnf( x, n ) {
139141
}
140142
// The maximum absolute single-precision float is ~3.4e38. Accordingly, any possible finite `x` rounded to the nearest >=10^39 is 0.0.
141143
if ( n > MAX_EXP ) {
142-
return f32( f32( 0.0 ) * x ); // preserve the sign (same behavior as roundf)
144+
return f32( ZERO * x ); // preserve the sign (same behavior as roundf)
143145
}
144146
// If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding...
145147
if ( n < MIN_EXP ) {
146-
s = powf( f32( 10.0 ), -( n + MAX_EXP ) );
148+
s = powf( TEN, -( n + MAX_EXP ) );
147149
y = f32( f32( x * HUGE ) * s ); // order of operation matters!
148150
if ( isInfinitef( y ) ) {
149151
return x;
150152
}
151153
return f32( f32( roundf( y ) / HUGE ) / s );
152154
}
153-
s = powf( f32( 10.0 ), -n );
155+
s = powf( TEN, -n );
154156
y = f32( x * s );
155157
if ( isInfinitef( y ) ) {
156158
return x;

lib/node_modules/@stdlib/math/base/special/roundnf/src/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static const float HUGE_VALUE = 1.0e+38f;
5252
*
5353
* <!-- <note> -->
5454
*
55-
* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) is \\(0.30000001192092896\\) and not \\(0.3\\). While possibly unexpected, this is not a bug. The behavior stems from the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\mathrm{roundf}\\).
55+
* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-7)\\) is \\(0.30000001192092896\\) and not \\(0.3\\). While possibly unexpected, this is not a bug. The behavior stems from the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\mathrm{roundf}\\).
5656
*
5757
* <!-- </note> -->
5858
*
@@ -108,7 +108,6 @@ float stdlib_base_roundnf( const float x, const int32_t n ) {
108108
if ( stdlib_base_is_nanf( x ) ) {
109109
return 0.0f / 0.0f; // NaN
110110
}
111-
112111
if (
113112
// Handle infinites...
114113
stdlib_base_is_infinitef( x ) ||

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,36 +120,36 @@ tape( 'the function supports rounding a numeric value to a desired number of dec
120120
actual = roundnf( PI, -2 );
121121
expected = float64ToFloat32( 3.14 );
122122
delta = ulpdiff( actual, expected );
123-
t.strictEqual( delta, 0.0, 'equals 3.14 within float32 precision' );
123+
t.strictEqual( delta, 0, 'returns expected value' );
124124

125125
actual = roundnf( -PI, -2 );
126126
expected = float64ToFloat32( -3.14 );
127127
delta = ulpdiff( actual, expected );
128-
t.strictEqual( delta, 0.0, 'equals -3.14 within float32 precision' );
128+
t.strictEqual( delta, 0, 'returns expected value' );
129129

130130
actual = roundnf( float64ToFloat32( 9.99999 ), -2 );
131131
expected = float64ToFloat32( 10.0 );
132132
delta = ulpdiff( actual, expected );
133-
t.strictEqual( delta, 0.0, 'equals 10 within float32 precision' );
133+
t.strictEqual( delta, 0, 'returns expected value' );
134134

135135
actual = roundnf( float64ToFloat32( -9.99999 ), -2 );
136136
expected = float64ToFloat32( -10.0 );
137137
delta = ulpdiff( actual, expected );
138-
t.strictEqual( delta, 0.0, 'equals -10 within float32 precision' );
138+
t.strictEqual( delta, 0, 'returns expected value' );
139139

140140
actual = roundnf( 0.0, 2 );
141141
expected = 0.0;
142-
t.strictEqual( actual, expected, 'equals 0' );
142+
t.strictEqual( actual, expected, 'returns expected value' );
143143

144144
actual = roundnf( float64ToFloat32( 12368.0 ), -3 );
145145
expected = float64ToFloat32( 12368.0 );
146146
delta = ulpdiff( actual, expected );
147-
t.strictEqual( delta, 0.0, 'equals 12368 within float32 precision' );
147+
t.strictEqual( delta, 0, 'returns expected value' );
148148

149149
actual = roundnf( float64ToFloat32( -12368.0 ), -3 );
150150
expected = float64ToFloat32( -12368.0 );
151151
delta = ulpdiff( actual, expected );
152-
t.strictEqual( delta, 0.0, 'equals -12368 within float32 precision' );
152+
t.strictEqual( delta, 0, 'returns expected value' );
153153

154154
t.end();
155155
});
@@ -161,10 +161,10 @@ tape( 'rounding a numeric value to a desired number of decimals can result in un
161161
var x;
162162

163163
x = float64ToFloat32( 0.2 + 0.1 ); // => 0.30000000000000004 as float64, becomes 0.30000001192092896 as float32
164-
actual = roundnf( x, -16 );
164+
actual = roundnf( x, -7 );
165165
expected = float64ToFloat32( 0.3000000119209290 );
166166
delta = ulpdiff( actual, expected );
167-
t.ok( delta <= 1.0, 'equals 0.3000000119209290 (within 1 ulp) and not exactly 0.3' );
167+
t.ok( delta <= 1, 'returns expected value' );
168168

169169
t.end();
170170
});
@@ -176,28 +176,28 @@ tape( 'the function supports rounding a numeric value to a desired number of dig
176176

177177
actual = roundnf( PI, 3 );
178178
expected = 0.0;
179-
t.strictEqual( actual, expected, 'equals 0' );
179+
t.strictEqual( actual, expected, 'returns expected value' );
180180

181181
actual = roundnf( float64ToFloat32( 12368.0 ), 3 );
182182
expected = float64ToFloat32( 12000.0 );
183183
delta = ulpdiff( actual, expected );
184-
t.ok( delta <= 1.0, 'equals 12000 within 1 ulp' );
184+
t.ok( delta <= 1, 'returns expected value' );
185185

186186
actual = roundnf( float64ToFloat32( 12368.0 ), 1 );
187187
expected = float64ToFloat32( 12370.0 );
188-
t.strictEqual( actual, expected, 'equals 12370' );
188+
t.strictEqual( actual, expected, 'returns expected value' );
189189

190190
actual = roundnf( -PI, 3 );
191-
t.strictEqual( isNegativeZerof( actual ), true, 'equals -0' );
191+
t.strictEqual( isNegativeZerof( actual ), true, 'returns expected value' );
192192

193193
actual = roundnf( float64ToFloat32( -12368.0 ), 3 );
194194
expected = float64ToFloat32( -12000.0 );
195195
delta = ulpdiff( actual, expected );
196-
t.ok( delta <= 1.0, 'equals -12000 within 1 ulp' );
196+
t.ok( delta <= 1, 'returns expected value' );
197197

198198
actual = roundnf( float64ToFloat32( -12368.0 ), 1 );
199199
expected = float64ToFloat32( -12370.0 );
200-
t.strictEqual( actual, expected, 'equals -12370' );
200+
t.strictEqual( actual, expected, 'returns expected value' );
201201

202202
t.end();
203203
});
@@ -213,7 +213,7 @@ tape( 'the function returns the input value if provided an `n` which is less tha
213213
x = float64ToFloat32( (1.0+randu()) * pow( 10.0, exp ) );
214214
n = -(round( randu()*50.0 ) + 46); // n < -45
215215
v = roundnf( x, n );
216-
t.strictEqual( v, x, 'returns input value when provided x='+x+', n='+n+'.' );
216+
t.strictEqual( v, x, 'returns expected value when provided x='+x+', n='+n+'.' );
217217
}
218218
t.end();
219219
});
@@ -231,7 +231,7 @@ tape( 'if `x` is too large a float to have decimals and `n < 0`, the input value
231231
x = float64ToFloat32( sign * (1.0+randu()) * pow( 10.0, exp ) );
232232
n = -( round( randu()*45.0) ); // n in range [0, -45]
233233
v = roundnf( x, n );
234-
t.strictEqual( x, v, 'returns input value when provided x='+x+', n='+n+'.' );
234+
t.strictEqual( x, v, 'returns expected value when provided x='+x+', n='+n+'.' );
235235
}
236236
t.end();
237237
});
@@ -288,7 +288,7 @@ tape( 'the function supports rounding very small numbers (including subnormals)'
288288
actual = roundnf( x, n[i] );
289289
if ( i < expected.length ) {
290290
delta = ulpdiff( actual, expected[i] );
291-
t.ok( delta <= 2.0, 'x: '+x+'. n: '+n[i]+'. v: '+actual+'. expected: '+expected[i]+'. delta: '+delta+' ulps' );
291+
t.ok( delta <= 2, 'x: '+x+'. n: '+n[i]+'. v: '+actual+'. expected: '+expected[i]+'. delta: '+delta+' ulps' );
292292
} else {
293293
// Beyond float32 precision
294294
t.ok( true, 'x: '+x+'. n: '+n[i]+'. v: '+actual );
@@ -303,19 +303,19 @@ tape( 'if the function encounters overflow, the function returns the input value
303303

304304
x = float64ToFloat32( 3.1468234 );
305305
v = roundnf( x, -40 );
306-
t.strictEqual( v, x, 'returns the input value' );
306+
t.strictEqual( v, x, 'returns expected value' );
307307

308308
x = float64ToFloat32( -3.1468234 );
309309
v = roundnf( x, -40 );
310-
t.strictEqual( v, x, 'returns the input value' );
310+
t.strictEqual( v, x, 'returns expected value' );
311311

312312
x = float64ToFloat32( 16777216.0 ); // 2^24, exact float32
313313
v = roundnf( x, -30 );
314-
t.strictEqual( v, x, 'returns the input value' );
314+
t.strictEqual( v, x, 'returns expected value' );
315315

316316
x = float64ToFloat32( -16777216.0 );
317317
v = roundnf( x, -30 );
318-
t.strictEqual( v, x, 'returns the input value' );
318+
t.strictEqual( v, x, 'returns expected value' );
319319

320320
t.end();
321321
});

0 commit comments

Comments
 (0)