diff --git a/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/benchmark.js index 828cf147a069..2272360159ec 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pkg = require( './../package.json' ).name; var truncf = require( './../lib' ); @@ -41,10 +41,13 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500.0, { + 'dtype': 'float32' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = truncf( x ); + y = truncf( x[ i % x.length ] ); if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } @@ -62,10 +65,13 @@ bench( pkg+'::built-in', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500.0, { + 'dtype': 'float32' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = Math.trunc( x ); // eslint-disable-line stdlib/no-builtin-math + y = Math.trunc( x[ i % x.length ] ); // eslint-disable-line stdlib/no-builtin-math if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/benchmark.native.js index f97aa98b96d4..93e5946ab5d1 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, -500.0, 500.0, { + 'dtype': 'float32' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = truncf( x ); + y = truncf( x[ i % x.length ] ); if ( isnanf( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/c/benchmark.c index 246f021e6c39..32ce987ca4ad 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/c/benchmark.c @@ -91,14 +91,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float x[ 100 ]; float y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 1000.0f * rand_float() ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f * rand_float() ) - 500.0f; - y = truncf( x ); + y = truncf( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/c/native/benchmark.c index 43e484efa6cf..55b80f25940e 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/truncf/benchmark/c/native/benchmark.c @@ -92,14 +92,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float x[ 100 ]; float y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 1000.0f * rand_float() ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f * rand_float() ) - 500.0f; - y = stdlib_base_truncf( x ); + y = stdlib_base_truncf( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/truncf/test/test.js b/lib/node_modules/@stdlib/math/base/special/truncf/test/test.js index 993d0c75b5c0..32ef22a929c7 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/truncf/test/test.js @@ -38,37 +38,37 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function rounds a numeric value toward 0', function test( t ) { - t.strictEqual( truncf( -4.2 ), -4.0, 'equals -4' ); - t.strictEqual( truncf( 9.99999 ), 9.0, 'equals 9' ); + t.strictEqual( truncf( -4.2 ), -4.0, 'returns expected value' ); + t.strictEqual( truncf( 9.99999 ), 9.0, 'returns expected value' ); t.end(); }); tape( 'if provided `+0`, the function returns `+0`', function test( t ) { var v = truncf( 0.0 ); - t.strictEqual( isPositiveZerof( v ), true, 'equals +0' ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); t.end(); }); tape( 'if provided `-0`, the function returns `-0`', function test( t ) { var v = truncf( -0.0 ); - t.strictEqual( isNegativeZerof( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { var v = truncf( NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { var v = truncf( PINF ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { var v = truncf( NINF ); - t.strictEqual( v, NINF, 'returns -infinity' ); + t.strictEqual( v, NINF, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/truncf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/truncf/test/test.native.js index c79e8726f11b..a0b2e56d92db 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/truncf/test/test.native.js @@ -47,37 +47,37 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function rounds a numeric value toward 0', opts, function test( t ) { - t.strictEqual( truncf( -4.2 ), -4.0, 'equals -4' ); - t.strictEqual( truncf( 9.99999 ), 9.0, 'equals 9' ); + t.strictEqual( truncf( -4.2 ), -4.0, 'returns expected value' ); + t.strictEqual( truncf( 9.99999 ), 9.0, 'returns expected value' ); t.end(); }); tape( 'if provided `+0`, the function returns `+0`', opts, function test( t ) { var v = truncf( 0.0 ); - t.strictEqual( isPositiveZerof( v ), true, 'equals +0' ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); t.end(); }); tape( 'if provided `-0`, the function returns `-0`', opts, function test( t ) { var v = truncf( -0.0 ); - t.strictEqual( isNegativeZerof( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { var v = truncf( NaN ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { var v = truncf( PINF ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { var v = truncf( NINF ); - t.strictEqual( v, NINF, 'returns -infinity' ); + t.strictEqual( v, NINF, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/benchmark.js index e626f741533a..373810886628 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var truncn = require( './../lib' ); @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, -5.0e6, 5.0e6 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1.0e7 ) - 5.0e6; - y = truncn( x, -2 ); + y = truncn( x[ i % x.length ], -2 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/benchmark.native.js index 7a777d748df1..cd855a3ad376 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, -5.0e6, 5.0e6 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu() * 1.0e7 ) - 5.0e6; - y = truncn( x, -2 ); + y = truncn( x[ i % x.length ], -2 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/c/native/benchmark.c index e0a037639bf9..f28cea8acbfa 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/truncn/benchmark/c/native/benchmark.c @@ -90,16 +90,19 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double v[ 100 ]; double elapsed; double t; - double v; double y; int i; + for ( i = 0; i < 100; i++ ) { + v[ i ] = ( 1.0e7 * rand_double() ) - 5.0e6; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - v = ( 1.0e7 * rand_double() ) - 5.0e6; - y = stdlib_base_truncn( v, -2 ); + y = stdlib_base_truncn( v[ i%100 ], -2 ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/truncn/test/test.js b/lib/node_modules/@stdlib/math/base/special/truncn/test/test.js index 529de0308604..6a42f2fef182 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncn/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/truncn/test/test.js @@ -47,13 +47,13 @@ tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { var v; v = truncn( NaN, -2 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncn( 12368.0, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncn( NaN, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -62,23 +62,23 @@ tape( 'the function returns `NaN` if provided `n = +-infinity`', function test( var v; v = truncn( PI, PINF ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncn( PI, NINF ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { var v = truncn( PINF, 5 ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { var v = truncn( NINF, -3 ); - t.strictEqual( v, NINF, 'returns -infinity' ); + t.strictEqual( v, NINF, 'returns expected value' ); t.end(); }); @@ -86,13 +86,13 @@ tape( 'the function returns `-0` if provided `-0`', function test( t ) { var v; v = truncn( -0.0, 0 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = truncn( -0.0, -2 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = truncn( -0.0, 2 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); t.end(); }); @@ -101,35 +101,35 @@ tape( 'the function returns `+0` if provided `+0`', function test( t ) { var v; v = truncn( 0.0, 0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = truncn( +0.0, -2 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = truncn( +0.0, 2 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function supports rounding a numeric value to a desired number of decimals', function test( t ) { - t.strictEqual( truncn( PI, -4 ), 3.1415, 'equals 3.1415' ); - t.strictEqual( truncn( -PI, -2 ), -3.14, 'equals -3.14' ); - t.strictEqual( truncn( 9.99999, -2 ), 9.99, 'equals 9.99' ); - t.strictEqual( truncn( -9.99999, -2 ), -9.99, 'equals -9.99' ); - t.strictEqual( truncn( 0.0, 2 ), 0.0, 'equals 0' ); - t.strictEqual( truncn( 12368.0, -3 ), 12368.0, 'equals 12368' ); - t.strictEqual( truncn( -12368.0, -3 ), -12368.0, 'equals -12368' ); + t.strictEqual( truncn( PI, -4 ), 3.1415, 'returns expected value' ); + t.strictEqual( truncn( -PI, -2 ), -3.14, 'returns expected value' ); + t.strictEqual( truncn( 9.99999, -2 ), 9.99, 'returns expected value' ); + t.strictEqual( truncn( -9.99999, -2 ), -9.99, 'returns expected value' ); + t.strictEqual( truncn( 0.0, 2 ), 0.0, 'returns expected value' ); + t.strictEqual( truncn( 12368.0, -3 ), 12368.0, 'returns expected value' ); + t.strictEqual( truncn( -12368.0, -3 ), -12368.0, 'returns expected value' ); t.end(); }); tape( 'the function supports rounding a numeric value to a desired number of digits', function test( t ) { - t.strictEqual( truncn( PI, 4 ), 0.0, 'equals 0' ); - t.strictEqual( truncn( 12368.0, 3 ), 12000.0, 'equals 12000' ); - t.strictEqual( truncn( 12363.0, 1 ), 12360.0, 'equals 12360' ); - t.strictEqual( isPositiveZero( truncn( PI, 3 ) ), true, 'equals +0' ); - t.strictEqual( truncn( -12368.0, 3 ), -12000.0, 'equals -12000' ); - t.strictEqual( truncn( -12368.0, 1 ), -12360.0, 'equals -12360' ); + t.strictEqual( truncn( PI, 4 ), 0.0, 'returns expected value' ); + t.strictEqual( truncn( 12368.0, 3 ), 12000.0, 'returns expected value' ); + t.strictEqual( truncn( 12363.0, 1 ), 12360.0, 'returns expected value' ); + t.strictEqual( isPositiveZero( truncn( PI, 3 ) ), true, 'returns expected value' ); + t.strictEqual( truncn( -12368.0, 3 ), -12000.0, 'returns expected value' ); + t.strictEqual( truncn( -12368.0, 1 ), -12360.0, 'returns expected value' ); t.end(); }); @@ -144,7 +144,7 @@ tape( 'the function returns the input value if provided an `n` which is less tha x = (1.0+randu()) * pow( 10.0, exp ); n = -(round( randu()*1000.0 ) + 325); v = truncn( x, n ); - t.strictEqual( v, x, 'returns input value when provided x='+x+', n='+n+'.' ); + t.strictEqual( v, x, 'returns expected value when provided x='+x+', n='+n+'.' ); } t.end(); }); @@ -162,7 +162,7 @@ tape( 'if `x` is too large a double to have decimals and `n < 0`, the input valu x = sign * (1.0+randu()) * pow( 10.0, exp ); n = -( round( randu()*324.0) ); v = truncn( x, n ); - t.strictEqual( x, v, ' returns input value when provided x='+x+', n='+n+'.' ); + t.strictEqual( x, v, ' returns expected value when provided x='+x+', n='+n+'.' ); } t.end(); }); @@ -178,7 +178,7 @@ tape( 'if `n > 308` and `x < 0`, the function returns `-0`', function test( t ) x = -(1.0+randu()) * pow( 10.0, exp ); n = round( randu()*100.0 ) + 309; v = truncn( x, n ); - t.strictEqual( isNegativeZero( v ), true, ' returns -0 when provided x='+x+', n='+n+'.' ); + t.strictEqual( isNegativeZero( v ), true, ' returns expected value when provided x='+x+', n='+n+'.' ); } t.end(); }); @@ -194,7 +194,7 @@ tape( 'if `n > 308` and `x > 0`, the function returns `+0`', function test( t ) x = (1.0+randu()) * pow( 10.0, exp ); n = round( randu()*100.0 ) + 309; v = truncn( x, n ); - t.strictEqual( isPositiveZero( v ), true, ' returns +0 when provided x='+x+', n='+n+'.' ); + t.strictEqual( isPositiveZero( v ), true, ' returns expected value when provided x='+x+', n='+n+'.' ); } t.end(); }); @@ -253,19 +253,19 @@ tape( 'if the function encounters overflow, the function returns the input value x = 3.1468234343023397; v = truncn( x, -314 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = -3.1468234343023397; v = truncn( x, -314 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = 9007199254740000; v = truncn( x, -300 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = -9007199254740000; v = truncn( x, -300 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/truncn/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/truncn/test/test.native.js index 7dd564ee1555..82ec5a8dd13f 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncn/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/truncn/test/test.native.js @@ -62,13 +62,13 @@ tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) { tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { var v = truncn( PINF, 5 ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { var v = truncn( NINF, -3 ); - t.strictEqual( v, NINF, 'returns -infinity' ); + t.strictEqual( v, NINF, 'returns expected value' ); t.end(); }); @@ -76,13 +76,13 @@ tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { var v; v = truncn( -0.0, 0 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = truncn( -0.0, -2 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = truncn( -0.0, 2 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); t.end(); }); @@ -91,35 +91,35 @@ tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { var v; v = truncn( 0.0, 0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = truncn( +0.0, -2 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = truncn( +0.0, 2 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function supports rounding a numeric value to a desired number of decimals', opts, function test( t ) { - t.strictEqual( truncn( PI, -4 ), 3.1415, 'equals 3.1415' ); - t.strictEqual( truncn( -PI, -2 ), -3.14, 'equals -3.14' ); - t.strictEqual( truncn( 9.99999, -2 ), 9.99, 'equals 9.99' ); - t.strictEqual( truncn( -9.99999, -2 ), -9.99, 'equals -9.99' ); - t.strictEqual( truncn( 0.0, 2 ), 0.0, 'equals 0' ); - t.strictEqual( truncn( 12368.0, -3 ), 12368.0, 'equals 12368' ); - t.strictEqual( truncn( -12368.0, -3 ), -12368.0, 'equals -12368' ); + t.strictEqual( truncn( PI, -4 ), 3.1415, 'returns expected value' ); + t.strictEqual( truncn( -PI, -2 ), -3.14, 'returns expected value' ); + t.strictEqual( truncn( 9.99999, -2 ), 9.99, 'returns expected value' ); + t.strictEqual( truncn( -9.99999, -2 ), -9.99, 'returns expected value' ); + t.strictEqual( truncn( 0.0, 2 ), 0.0, 'returns expected value' ); + t.strictEqual( truncn( 12368.0, -3 ), 12368.0, 'returns expected value' ); + t.strictEqual( truncn( -12368.0, -3 ), -12368.0, 'returns expected value' ); t.end(); }); tape( 'the function supports rounding a numeric value to a desired number of digits', opts, function test( t ) { - t.strictEqual( truncn( PI, 4 ), 0.0, 'equals 0' ); - t.strictEqual( truncn( 12368.0, 3 ), 12000.0, 'equals 12000' ); - t.strictEqual( truncn( 12363.0, 1 ), 12360.0, 'equals 12360' ); - t.strictEqual( isPositiveZero( truncn( PI, 3 ) ), true, 'equals +0' ); - t.strictEqual( truncn( -12368.0, 3 ), -12000.0, 'equals -12000' ); - t.strictEqual( truncn( -12368.0, 1 ), -12360.0, 'equals -12360' ); + t.strictEqual( truncn( PI, 4 ), 0.0, 'returns expected value' ); + t.strictEqual( truncn( 12368.0, 3 ), 12000.0, 'returns expected value' ); + t.strictEqual( truncn( 12363.0, 1 ), 12360.0, 'returns expected value' ); + t.strictEqual( isPositiveZero( truncn( PI, 3 ) ), true, 'returns expected value' ); + t.strictEqual( truncn( -12368.0, 3 ), -12000.0, 'returns expected value' ); + t.strictEqual( truncn( -12368.0, 1 ), -12360.0, 'returns expected value' ); t.end(); }); @@ -134,7 +134,7 @@ tape( 'the function returns the input value if provided an `n` which is less tha x = (1.0+randu()) * pow( 10.0, exp ); n = -(round( randu()*1000.0 ) + 325); v = truncn( x, n ); - t.strictEqual( v, x, 'returns input value when provided x='+x+', n='+n+'.' ); + t.strictEqual( v, x, 'returns expected value when provided x='+x+', n='+n+'.' ); } t.end(); }); @@ -152,7 +152,7 @@ tape( 'if `x` is too large a double to have decimals and `n < 0`, the input valu x = sign * (1.0+randu()) * pow( 10.0, exp ); n = -( round( randu()*324.0) ); v = truncn( x, n ); - t.strictEqual( x, v, ' returns input value when provided x='+x+', n='+n+'.' ); + t.strictEqual( x, v, ' returns expected value when provided x='+x+', n='+n+'.' ); } t.end(); }); @@ -168,7 +168,7 @@ tape( 'if `n > 308` and `x < 0`, the function returns `-0`', opts, function test x = -(1.0+randu()) * pow( 10.0, exp ); n = round( randu()*100.0 ) + 309; v = truncn( x, n ); - t.strictEqual( isNegativeZero( v ), true, ' returns -0 when provided x='+x+', n='+n+'.' ); + t.strictEqual( isNegativeZero( v ), true, ' returns expected value when provided x='+x+', n='+n+'.' ); } t.end(); }); @@ -184,7 +184,7 @@ tape( 'if `n > 308` and `x > 0`, the function returns `+0`', opts, function test x = (1.0+randu()) * pow( 10.0, exp ); n = round( randu()*100.0 ) + 309; v = truncn( x, n ); - t.strictEqual( isPositiveZero( v ), true, ' returns +0 when provided x='+x+', n='+n+'.' ); + t.strictEqual( isPositiveZero( v ), true, ' returns expected value when provided x='+x+', n='+n+'.' ); } t.end(); }); @@ -243,19 +243,19 @@ tape( 'if the function encounters overflow, the function returns the input value x = 3.1468234343023397; v = truncn( x, -314 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = -3.1468234343023397; v = truncn( x, -314 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = 9007199254740000; v = truncn( x, -300 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = -9007199254740000; v = truncn( x, -300 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/benchmark.js index dffc8f7af2cb..54f8faa60692 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var truncsd = require( './../lib' ); @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, -5.0e6, 5.0e6 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1.0e7 ) - 5.0e6; - y = truncsd( x, 2, 2 ); + y = truncsd( x[ i % x.length ], 2, 2 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/benchmark.native.js index ad3d33e52b28..ec3beacdc645 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, -5.0e6, 5.0e6 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu() * 1.0e7 ) - 5.0e6; - y = truncsd( x, 2, 2 ); + y = truncsd( x[ i % x.length ], 2, 2 ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/c/native/benchmark.c index 64921dfb38ba..1285350841af 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/truncsd/benchmark/c/native/benchmark.c @@ -90,16 +90,19 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double x[ 100 ]; double elapsed; - double x; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 1.0e7 * rand_double() ) - 5.0e6; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1.0e7 * rand_double() ) - 5.0e6; - y = stdlib_base_truncsd( x, 2, 2 ); + y = stdlib_base_truncsd( x[ i%100 ], 2, 2 ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/truncsd/test/test.js b/lib/node_modules/@stdlib/math/base/special/truncsd/test/test.js index 367bc0295359..343f1f47f64b 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncsd/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/truncsd/test/test.js @@ -42,25 +42,25 @@ tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { var v; v = truncsd( NaN, 2, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( 12368.0, NaN, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( NaN, NaN, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( NaN, NaN, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( NaN, 2, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( 3.14, NaN, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( 3.14, 2, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -69,10 +69,10 @@ tape( 'the function returns `NaN` if provided `n = +-infinity`', function test( var v; v = truncsd( PI, PINF, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( PI, NINF, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -81,10 +81,10 @@ tape( 'the function returns `NaN` if provided `n < 1`', function test( t ) { var v; v = truncsd( PI, 0, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( PI, -1, 10 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -93,10 +93,10 @@ tape( 'the function returns `NaN` if provided `b = +-infinity`', function test( var v; v = truncsd( PI, 2, PINF ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( PI, 2, NINF ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -105,23 +105,23 @@ tape( 'the function returns `NaN` if provided `b <= 0`', function test( t ) { var v; v = truncsd( PI, 2, 0 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = truncsd( PI, 2, -1 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `+infinity` if provided `+infinity`', function test( t ) { var v = truncsd( PINF, 5, 10 ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', function test( t ) { var v = truncsd( NINF, 3, 10 ); - t.strictEqual( v, NINF, 'returns -infinity' ); + t.strictEqual( v, NINF, 'returns expected value' ); t.end(); }); @@ -129,10 +129,10 @@ tape( 'the function returns `-0` if provided `-0`', function test( t ) { var v; v = truncsd( -0.0, 1, 10 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = truncsd( -0.0, 2, 10 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); t.end(); }); @@ -141,10 +141,10 @@ tape( 'the function returns `+0` if provided `+0`', function test( t ) { var v; v = truncsd( 0.0, 1, 10 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = truncsd( +0.0, 2, 10 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); @@ -196,19 +196,19 @@ tape( 'if the function encounters overflow, the function returns the input value x = 3.1468234343023397; v = truncsd( x, 1000, 10 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = -3.1468234343023397; v = truncsd( x, 1000, 10 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = 9007199254740000; v = truncsd( x, 320, 10 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = -9007199254740000; v = truncsd( x, 320, 10 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/truncsd/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/truncsd/test/test.native.js index d78e956ec93b..6231f6ffe2ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/truncsd/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/truncsd/test/test.native.js @@ -81,13 +81,13 @@ tape( 'the function returns `NaN` if provided `b <= 0`', opts, function test( t tape( 'the function returns `+infinity` if provided `+infinity`', opts, function test( t ) { var v = truncsd( PINF, 5, 10 ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); tape( 'the function returns `-infinity` if provided `-infinity`', opts, function test( t ) { var v = truncsd( NINF, 3, 10 ); - t.strictEqual( v, NINF, 'returns -infinity' ); + t.strictEqual( v, NINF, 'returns expected value' ); t.end(); }); @@ -95,10 +95,10 @@ tape( 'the function returns `-0` if provided `-0`', opts, function test( t ) { var v; v = truncsd( -0.0, 1, 10 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = truncsd( -0.0, 2, 10 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); t.end(); }); @@ -107,10 +107,10 @@ tape( 'the function returns `+0` if provided `+0`', opts, function test( t ) { var v; v = truncsd( 0.0, 1, 10 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = truncsd( +0.0, 2, 10 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); @@ -162,19 +162,19 @@ tape( 'if the function encounters overflow, the function returns the input value x = 3.1468234343023397; v = truncsd( x, 1000, 10 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = -3.1468234343023397; v = truncsd( x, 1000, 10 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = 9007199254740000; v = truncsd( x, 320, 10 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); x = -9007199254740000; v = truncsd( x, 320, 10 ); - t.strictEqual( v, x, 'returns the input value' ); + t.strictEqual( v, x, 'returns expected value' ); t.end(); });