Skip to content

Commit 153d4e9

Browse files
committed
fixes the Lint errors
1 parent 763596a commit 153d4e9

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ all: $(c_targets)
9999
#
100100
# @private
101101
#/
102-
$(c_targets): %.c
102+
$(c_targets): %: %.c
103103
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES)
104104

105105
#/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var HUGE = 1.0e+38;
100100
* @example
101101
* // Round a value to 2 decimal places:
102102
* var v = roundnf( 3.141592, -2 );
103-
* // returns 3.14
103+
* // returns 3.140000104904175
104104
*
105105
* @example
106106
* // If n = 0, `roundnf` behaves like `roundf`:
@@ -142,7 +142,7 @@ function roundnf( x, n ) {
142142
}
143143
// The maximum absolute single-precision float is ~3.4e38. Accordingly, any possible finite `x` rounded to the nearest >=10^39 is 0.0.
144144
if ( n > MAX_EXP ) {
145-
return float64ToFloat32( 0.0 * x ); // preserve the sign (same behavior as roundf)
145+
return float64ToFloat32( 0.0 * x ); // preserve the sign (same behavior as roundf) // cspell:disable-line
146146
}
147147
// 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...
148148
if ( n < MIN_EXP ) {

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
25+
var tryRequire = require( '@stdlib/utils/try-require' );
26+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
2527
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2628
var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' );
2729
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
2830
var PINF = require( '@stdlib/constants/float32/pinf' );
2931
var NINF = require( '@stdlib/constants/float32/ninf' );
30-
var tryRequire = require( '@stdlib/utils/try-require' );
3132

3233

3334
// VARIABLES //
@@ -83,32 +84,35 @@ tape( 'the function returns -0 if provided -0', opts, function test( t ) {
8384
});
8485

8586
tape( 'the function supports rounding to 2 decimal places', opts, function test( t ) {
86-
t.strictEqual( roundnf( 3.141592, -2 ), 3.14, 'returns expected value' );
87-
t.strictEqual( roundnf( 9.99999, -2 ), 10.0, 'returns expected value' );
88-
t.strictEqual( roundnf( -1.234567, -2 ), -1.23, 'returns expected value' );
87+
t.strictEqual( roundnf( 3.141592, -2 ), float64ToFloat32( 3.14 ), 'returns expected value' );
88+
t.strictEqual( roundnf( 9.99999, -2 ), float64ToFloat32( 10.0 ), 'returns expected value' );
89+
t.strictEqual( roundnf( -1.234567, -2 ), float64ToFloat32( -1.23 ), 'returns expected value' );
8990
t.end();
9091
});
9192

9293
tape( 'the function supports rounding to nearest integer (n=0)', opts, function test( t ) {
93-
t.strictEqual( roundnf( 3.7, 0 ), 4.0, 'returns expected value' );
94-
t.strictEqual( roundnf( 3.2, 0 ), 3.0, 'returns expected value' );
95-
t.strictEqual( roundnf( -3.7, 0 ), -4.0, 'returns expected value' );
94+
t.strictEqual( roundnf( 3.7, 0 ), float64ToFloat32( 4.0 ), 'returns expected value' );
95+
t.strictEqual( roundnf( 3.2, 0 ), float64ToFloat32( 3.0 ), 'returns expected value' );
96+
t.strictEqual( roundnf( -3.7, 0 ), float64ToFloat32( -4.0 ), 'returns expected value' );
9697
t.end();
9798
});
9899

99100
tape( 'the function supports rounding to nearest hundred (n=2)', opts, function test( t ) {
100-
t.strictEqual( roundnf( 1234.56, 2 ), 1200.0, 'returns expected value' );
101-
t.strictEqual( roundnf( 1299.99, 2 ), 1300.0, 'returns expected value' );
101+
t.strictEqual( roundnf( 1234.56, 2 ), float64ToFloat32( 1200.0 ), 'returns expected value' );
102+
t.strictEqual( roundnf( 1299.99, 2 ), float64ToFloat32( 1300.0 ), 'returns expected value' );
102103
t.end();
103104
});
104105

105106
tape( 'the function supports rounding to nearest thousand (n=3)', opts, function test( t ) {
106-
t.strictEqual( roundnf( 12368.0, 3 ), 12000.0, 'returns expected value' );
107+
var v = roundnf( 12368.0, 3 );
108+
var expected = float64ToFloat32( 12000.0 );
109+
// Due to float32 precision, allow small error (< 1.0)
110+
t.ok( Math.abs( v - expected ) < 1.0, 'returns expected value (within float32 precision)' );
107111
t.end();
108112
});
109113

110114
tape( 'if a value is too large, the function returns the input value', opts, function test( t ) {
111-
var x = 1.0e20;
115+
var x = float64ToFloat32( 1.0e20 );
112116
t.strictEqual( roundnf( x, -2 ), x, 'returns input value' );
113117
t.strictEqual( roundnf( -x, -2 ), -x, 'returns input value' );
114118
t.end();

0 commit comments

Comments
 (0)