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 abs = require( './../lib' );
Expand All @@ -34,10 +34,13 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -5000.0, 5000.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*10000.0 ) - 5000.0;
y = abs( x );
y = abs( x[ i%x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -5000.0, 5000.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 10000.0 ) - 5000.0;
y = abs( x );
y = abs( x[ i%x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
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 x;
double x[ 100 ];
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 10000.0 * rand_double() ) - 5000.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 10000.0 * rand_double() ) - 5000.0;
y = stdlib_base_fast_abs( x );
y = stdlib_base_fast_abs( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
16 changes: 8 additions & 8 deletions lib/node_modules/@stdlib/math/base/special/fast/abs/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ tape( 'main export is a function', function test( t ) {
});

tape( 'the function computes the absolute value of a number', function test( t ) {
t.strictEqual( abs( -2.0 ), 2.0, 'negative number' );
t.strictEqual( abs( 3.0 ), 3.0, 'positive number' );
t.strictEqual( abs( 0.0 ), 0.0, 'zero' );
t.strictEqual( abs( -PI ), PI, 'pi' );
t.strictEqual( abs( -2.0 ), 2.0, 'returns expected value' );
t.strictEqual( abs( 3.0 ), 3.0, 'returns expected value' );
t.strictEqual( abs( 0.0 ), 0.0, 'returns expected value' );
t.strictEqual( abs( -PI ), PI, 'returns expected value' );
t.end();
});

tape( 'the function returns `-0` if provided `-0` (not IEEE 754 compliant)', function test( t ) {
t.strictEqual( isNegativeZero( abs( -0.0 ) ), true, 'returns negative zero' );
t.strictEqual( isNegativeZero( abs( -0.0 ) ), true, 'returns expected value' );
t.end();
});

tape( 'the function computes the absolute value of `infinity`', function test( t ) {
t.strictEqual( abs( PINF ), PINF, 'returns +infinity' );
t.strictEqual( abs( NINF ), PINF, 'returns +infinity' );
t.strictEqual( abs( PINF ), PINF, 'returns expected value' );
t.strictEqual( abs( NINF ), PINF, 'returns expected value' );
t.end();
});

tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
var v = abs( NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,26 @@ tape( 'main export is a function', opts, function test( t ) {
});

tape( 'the function computes the absolute value of a number', opts, function test( t ) {
t.strictEqual( abs( -2.0 ), 2.0, 'negative number' );
t.strictEqual( abs( 3.0 ), 3.0, 'positive number' );
t.strictEqual( abs( 0.0 ), 0.0, 'zero' );
t.strictEqual( abs( -PI ), PI, 'pi' );
t.strictEqual( abs( -2.0 ), 2.0, 'returns expected value' );
t.strictEqual( abs( 3.0 ), 3.0, 'returns expected value' );
t.strictEqual( abs( 0.0 ), 0.0, 'returns expected value' );
t.strictEqual( abs( -PI ), PI, 'returns expected value' );
t.end();
});

tape( 'the function returns `-0` if provided `-0` (not IEEE 754 compliant)', opts, function test( t ) {
t.strictEqual( isNegativeZero( abs( -0.0 ) ), true, 'returns negative zero' );
t.strictEqual( isNegativeZero( abs( -0.0 ) ), true, 'returns expected value' );
t.end();
});

tape( 'the function computes the absolute value of `infinity`', opts, function test( t ) {
t.strictEqual( abs( PINF ), PINF, 'returns +infinity' );
t.strictEqual( abs( NINF ), PINF, 'returns +infinity' );
t.strictEqual( abs( PINF ), PINF, 'returns expected value' );
t.strictEqual( abs( NINF ), PINF, 'returns expected value' );
t.end();
});

tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) {
var v = abs( NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, '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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var acosh = require( './../lib' );
Expand All @@ -34,10 +34,13 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 1.0, 100.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = 1.0 + ( randu()*100.0 );
y = acosh( x );
y = acosh( x[ i%x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, 1.0, 100.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = 1.0 + ( randu()*100.0 );
y = acosh( x );
y = acosh( x[ i%x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
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 x;
double x[ 100 ];
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 100.0 * rand_double() ) + 1.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0 * rand_double() ) + 1.0;
y = stdlib_base_fast_acosh( x );
y = stdlib_base_fast_acosh( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ tape( 'the function computes the hyperbolic arccosine for huge values', function

tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
var v = acosh( NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -152,7 +152,7 @@ tape( 'the function returns `NaN` if provided value less than `1`', function tes

for ( i = 0; i < 1e3; i++ ) {
v = -(randu()*1.0e6) + (1.0-EPS);
t.strictEqual( isnan( acosh( v ) ), true, 'returns NaN when provided '+v );
t.strictEqual( isnan( acosh( v ) ), true, 'returns expected value when provided '+v );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ tape( 'the function computes the hyperbolic arccosine for huge values', opts, fu

tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) {
var v = acosh( NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -161,7 +161,7 @@ tape( 'the function returns `NaN` if provided value less than `1`', opts, functi

for ( i = 0; i < 1e3; i++ ) {
v = -(randu()*1.0e6) + (1.0-EPS);
t.strictEqual( isnan( acosh( v ) ), true, 'returns NaN when provided '+v );
t.strictEqual( isnan( acosh( v ) ), true, 'returns expected value when provided '+v );
}
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var asinh = require( './../lib' );
Expand All @@ -34,10 +34,13 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -100.0, 100.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*200.0 ) - 100.0;
y = asinh( x );
y = asinh( x[ i%x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -100.0, 100.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*200.0 ) - 100.0;
y = asinh( x );
y = asinh( x[ i%x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
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 x;
double x[ 100 ];
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( rand_double() * 200.0 ) - 100.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double() * 200.0 ) - 100.0;
y = stdlib_base_fast_asinh( x );
y = stdlib_base_fast_asinh( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ tape( 'main export is a function', function test( t ) {
tape( 'the function underflows if provided a number which is negligible compared to unity', function test( t ) {
var x = EPS / 2.0;
var v = asinh( x );
t.strictEqual( v, 0.0, 'returns 0' );
t.strictEqual( v, 0.0, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -278,36 +278,36 @@ tape( 'the function computes the hyperbolic arcsine on the interval `[-100.0,-28
tape( 'the function overflows if provided a value which, when squared, overflows', function test( t ) {
var x = 1.0e200;
var v = asinh( x );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );
t.end();
});

tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
var v = asinh( NaN );
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 = asinh( 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 = asinh( NINF );
t.strictEqual( v, NINF, 'returns -infinity' );
t.strictEqual( v, NINF, 'returns expected value' );
t.end();
});

tape( 'the function returns `-0` if provided `-0`', function test( t ) {
var v = asinh( -0 );
t.strictEqual( isNegativeZero( v ), true, 'returns -0' );
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `+0` if provided `+0`', function test( t ) {
var v = asinh( +0 );
t.strictEqual( isPositiveZero( v ), true, 'returns +0' );
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
t.end();
});
Loading