Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 minn = require( './../lib' );
Expand All @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = uniform( 100, -500.0, 500.0 );
y = uniform( 100, -500.0, 500.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;
z = minn( x, y );
z = minn( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -58,11 +59,12 @@ bench( pkg+'::built-in', function benchmark( b ) {
var z;
var i;

x = uniform( 100, -500.0, 500.0 );
y = uniform( 100, -500.0, 500.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;
z = Math.min( x, y ); // eslint-disable-line stdlib/no-builtin-math
z = Math.min( x[ i%x.length ], y[ i%y.length ] ); // eslint-disable-line stdlib/no-builtin-math
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,20 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
y[ i ] = ( 1000.0*rand_double() ) - 500.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0*rand_double() ) - 500.0;
y = ( 1000.0*rand_double() ) - 500.0;
z = fmin( x, y );
z = fmin( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
44 changes: 22 additions & 22 deletions lib/node_modules/@stdlib/math/base/special/minn/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
var v;

v = minn( NaN, 3.14 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = minn( 3.14, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = minn( NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

v = minn( 3.14, 4.2, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -59,49 +59,49 @@ tape( 'the function returns `-Infinity` if provided `-Infinity`', function test(
var v;

v = minn( NINF, 3.14 );
t.strictEqual( v, NINF, 'returns -infinity' );
t.strictEqual( v, NINF, 'returns expected value' );

v = minn( 3.14, NINF );
t.strictEqual( v, NINF, 'returns -infinity' );
t.strictEqual( v, NINF, 'returns expected value' );

v = minn( NINF );
t.strictEqual( v, NINF, 'returns -infinity' );
t.strictEqual( v, NINF, 'returns expected value' );

v = minn( 3.14, 4.2, NINF );
t.strictEqual( v, NINF, 'returns -infinity' );
t.strictEqual( v, NINF, 'returns expected value' );

t.end();
});

tape( 'the function returns `+infinity` if not provided any arguments', function test( t ) {
var v = minn();
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );
t.end();
});

tape( 'the function returns a correctly signed zero', function test( t ) {
var v;

v = minn( +0.0, -0.0 );
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );

v = minn( -0.0, +0.0 );
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );

v = minn( -0.0, -0.0 );
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );

v = minn( +0.0, +0.0 );
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );

v = minn( -0.0 );
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );

v = minn( +0.0 );
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );

v = minn( +0.0, -0.0, +0.0 );
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -110,22 +110,22 @@ tape( 'the function returns the minimum value', function test( t ) {
var v;

v = minn( 4.2, 3.14 );
t.strictEqual( v, 3.14, 'returns min value' );
t.strictEqual( v, 3.14, 'returns expected value' );

v = minn( -4.2, 3.14 );
t.strictEqual( v, -4.2, 'returns min value' );
t.strictEqual( v, -4.2, 'returns expected value' );

v = minn( 3.14 );
t.strictEqual( v, 3.14, 'returns min value' );
t.strictEqual( v, 3.14, 'returns expected value' );

v = minn( PINF );
t.strictEqual( v, PINF, 'returns min value' );
t.strictEqual( v, PINF, 'returns expected value' );

v = minn( 4.2, 3.14, -1.0 );
t.strictEqual( v, -1.0, 'returns min value' );
t.strictEqual( v, -1.0, 'returns expected value' );

v = minn( 4.2, 3.14, -1.0, -3.14 );
t.strictEqual( v, -3.14, 'returns min value' );
t.strictEqual( v, -3.14, 'returns expected value' );

t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 isArray = require( '@stdlib/assert/is-array' );
var pkg = require( './../package.json' ).name;
var modf = require( './../lib' );
Expand All @@ -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 = modf( x );
y = modf( x[ i%x.length ] );
if ( typeof y !== 'object' ) {
b.fail( 'should return an array' );
}
Expand All @@ -56,12 +57,12 @@ bench( pkg+':assign', function benchmark( b ) {
var y;
var i;

x = uniform( 100, -5.0e6, 5.0e6 );
out = [ 0.0, 0.0 ];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1.0e7 ) - 5.0e6;
y = modf.assign( x, out, 1, 0 );
y = modf.assign( x[ i%x.length ], out, 1, 0 );
if ( typeof y !== 'object' ) {
b.fail( 'should return an array' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 isArray = require( '@stdlib/assert/is-array' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -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 = modf( x );
y = modf( x[ i%x.length ] );
if ( typeof y !== 'object' ) {
b.fail( 'should return an array' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,18 @@ static double rand_double( void ) {
static double benchmark( void ) {
double elapsed;
double iptr;
double x;
double x[ 100 ];
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 = modf( x, &iptr );
y = modf( x[ i%100 ], &iptr );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ static double rand_double( void ) {
static double benchmark( void ) {
double integral;
double elapsed;
double x;
double x[ 100 ];
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;
stdlib_base_modf( x, &integral, &y );
stdlib_base_modf( x[ i%100 ], &integral, &y );
if ( y != y || integral != integral) {
printf( "unexpected results\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ tape( 'if provided `+0`, the function returns `[+0,+0]`', function test( t ) {
out = [ 0.0, 0.0 ];
parts = modf( +0.0, out, 1, 0 );
t.equal( parts, out, 'returns output array' );
t.strictEqual( isPositiveZero( parts[0] ), true, 'returns +0' );
t.strictEqual( isPositiveZero( parts[1] ), true, 'returns +0' );
t.strictEqual( isPositiveZero( parts[0] ), true, 'returns expected value' );
t.strictEqual( isPositiveZero( parts[1] ), true, 'returns expected value' );
t.end();
});

Expand All @@ -171,8 +171,8 @@ tape( 'if provided `-0`, the function returns `[-0,-0]`', function test( t ) {
out = [ 0.0, 0.0 ];
parts = modf( -0.0, out, 1, 0 );
t.equal( parts, out, 'returns output array' );
t.strictEqual( isNegativeZero( parts[0] ), true, 'returns -0' );
t.strictEqual( isNegativeZero( parts[1] ), true, 'returns -0' );
t.strictEqual( isNegativeZero( parts[0] ), true, 'returns expected value' );
t.strictEqual( isNegativeZero( parts[1] ), true, 'returns expected value' );
t.end();
});

Expand All @@ -184,7 +184,7 @@ tape( 'if provided `+infinity`, the function returns `[+infinity,+0]`', function
parts = modf( PINF, out, 1, 0 );
t.equal( parts, out, 'returns output array' );
t.strictEqual( parts[0], PINF, 'returns +infinity' );
t.strictEqual( isPositiveZero( parts[1] ), true, 'returns +0' );
t.strictEqual( isPositiveZero( parts[1] ), true, 'returns expected value' );
t.end();
});

Expand All @@ -196,7 +196,7 @@ tape( 'if provided `-infinity`, the function returns `[-infinity,-0]`', function
parts = modf( NINF, out, 1, 0 );
t.equal( parts, out, 'returns output array' );
t.strictEqual( parts[0], NINF, 'returns -infinity' );
t.strictEqual( isNegativeZero( parts[1] ), true, 'returns -0' );
t.strictEqual( isNegativeZero( parts[1] ), true, 'returns expected value' );
t.end();
});

Expand All @@ -207,8 +207,8 @@ tape( 'if provided `NaN`, the function returns `[NaN,NaN]`', function test( t )
out = [ 0.0, 0.0 ];
parts = modf( NaN, out, 1, 0 );
t.equal( parts, out, 'returns output array' );
t.strictEqual( isnan( parts[0] ), true, 'returns NaN' );
t.strictEqual( isnan( parts[1] ), true, 'returns NaN' );
t.strictEqual( isnan( parts[0] ), true, 'returns expected value' );
t.strictEqual( isnan( parts[1] ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,35 +138,35 @@ tape( 'the function decomposes a number into integral and fractional parts (subn

tape( 'if provided `+0`, the function returns `[+0,+0]`', function test( t ) {
var parts = modf( +0.0 );
t.strictEqual( isPositiveZero( parts[0] ), true, 'returns +0' );
t.strictEqual( isPositiveZero( parts[1] ), true, 'returns +0' );
t.strictEqual( isPositiveZero( parts[0] ), true, 'returns expected value' );
t.strictEqual( isPositiveZero( parts[1] ), true, 'returns expected value' );
t.end();
});

tape( 'if provided `-0`, the function returns `[-0,-0]`', function test( t ) {
var parts = modf( -0.0 );
t.strictEqual( isNegativeZero( parts[0] ), true, 'returns -0' );
t.strictEqual( isNegativeZero( parts[1] ), true, 'returns -0' );
t.strictEqual( isNegativeZero( parts[0] ), true, 'returns expected value' );
t.strictEqual( isNegativeZero( parts[1] ), true, 'returns expected value' );
t.end();
});

tape( 'if provided `+infinity`, the function returns `[+infinity,+0]`', function test( t ) {
var parts = modf( PINF );
t.strictEqual( parts[0], PINF, 'returns +infinity' );
t.strictEqual( isPositiveZero( parts[1] ), true, 'returns +0' );
t.strictEqual( isPositiveZero( parts[1] ), true, 'returns expected value' );
t.end();
});

tape( 'if provided `-infinity`, the function returns `[-infinity,-0]`', function test( t ) {
var parts = modf( NINF );
t.strictEqual( parts[0], NINF, 'returns -infinity' );
t.strictEqual( isNegativeZero( parts[1] ), true, 'returns -0' );
t.strictEqual( isNegativeZero( parts[1] ), true, 'returns expected value' );
t.end();
});

tape( 'if provided `NaN`, the function returns `[NaN,NaN]`', function test( t ) {
var parts = modf( NaN );
t.strictEqual( isnan( parts[0] ), true, 'returns NaN' );
t.strictEqual( isnan( parts[1] ), true, 'returns NaN' );
t.strictEqual( isnan( parts[0] ), true, 'returns expected value' );
t.strictEqual( isnan( parts[1] ), true, 'returns expected value' );
t.end();
});
Loading