Skip to content
Closed
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,8 +21,9 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var pkg = require( './../package.json' ).name;
var cbrt = require( './../lib' );

Expand All @@ -37,14 +38,18 @@ var opts = {
// MAIN //

bench( pkg, function benchmark( b ) {
var x;
var values;
var y;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = cbrt( x );
y = cbrt( values[ i%values.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -58,14 +63,18 @@ bench( pkg, function benchmark( b ) {
});

bench( pkg+'::built-in', opts, function benchmark( b ) {
var x;
var values;
var y;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = Math.cbrt( x ); // eslint-disable-line stdlib/no-builtin-math
y = Math.cbrt( values[ i%values.length ]); // eslint-disable-line stdlib/no-builtin-math
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -39,14 +40,18 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var x;
var values;
var y;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( 1000.0*randu() ) - 500.0;
y = cbrt( x );
y = cbrt( values[ i%values.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include "stdlib/math/base/special/cbrt.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -89,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 ] = ( 1000.0*rand_double() ) - 500.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0*rand_double() ) - 500.0;
y = cbrt( x );
y = stdlib_base_cbrt( 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 @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include "stdlib/math/base/special/cbrt.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -94,16 +95,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 ] = ( 1000.0*rand_double() ) - 500.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0*rand_double() ) - 500.0;
y = cbrt( x );
y = stdlib_base_cbrt( 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 @@ -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 ] = ( 1000.0*rand_double() ) - 500.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0*rand_double() ) - 500.0;
y = stdlib_base_cbrt( x );
y = stdlib_base_cbrt( 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 @@ -383,7 +383,7 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', function t

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', opts, func

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var pkg = require( './../package.json' ).name;
var cbrtf = require( './../lib' );

Expand All @@ -37,14 +38,18 @@ var opts = {
// MAIN //

bench( pkg, function benchmark( b ) {
var x;
var values;
var y;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = cbrtf( x );
y = cbrtf( values[ i%values.length ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -58,14 +63,18 @@ bench( pkg, function benchmark( b ) {
});

bench( pkg+'::built-in', opts, function benchmark( b ) {
var x;
var values;
var y;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = Math.cbrt( x ); // eslint-disable-line stdlib/no-builtin-math
y = Math.cbrt( values[ i%values.length ] ); // eslint-disable-line stdlib/no-builtin-math
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -39,14 +40,18 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var x;
var values;
var y;
var i;

values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( 1000.0*randu() ) - 500.0;
y = cbrtf( x );
y = cbrtf( values[ i%values.length ] );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include "stdlib/math/base/special/cbrtf.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -89,16 +90,19 @@ static float rand_float( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
float x[ 100 ];
double elapsed;
float x;
float y;
double t;
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 = cbrtf( x );
y = stdlib_base_cbrtf( 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 @@ -90,16 +90,19 @@ static float rand_float( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
float x[ 100 ];
double elapsed;
float x;
float y;
double t;
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_cbrtf( x );
y = stdlib_base_cbrtf( 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 @@ -383,7 +383,7 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', function t

tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var v = cbrtf( NaN );
t.equal( isnanf( v ), true, 'returns NaN' );
t.equal( isnanf( v ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', opts, func

tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
var v = cbrtf( NaN );
t.equal( isnanf( v ), true, 'returns NaN' );
t.equal( isnanf( v ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ static float rand_float( void ) {
static double benchmark( void ) {
float complex x;
float complex y;
float v[ 100 ];
double elapsed;
double t;
float v;
int i;

for ( i = 0; i < 100; i++ ) {
v[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
v = ( 1000.0f*rand_float() ) - 500.0f;
x = v + v*I;
x = v[ i%100 ] + v[ i%100 ]*I;
y = stdlib_base_cceilf( x );
if ( crealf( y ) != crealf( y ) ) {
printf( "unexpected result\n" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ static double rand_double( void ) {
static double benchmark( void ) {
double complex x;
double complex y;
double v[ 100 ];
double elapsed;
double t;
double v;
int i;

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

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
v = ( 1000.0*rand_double() ) - 500.0;
x = v + v*I;
x = v[ i%100 ] + v[ i%100 ]*I;
y = stdlib_base_ceiln( creal( x ), -2 ) + stdlib_base_ceiln( cimag( x ), -2 )*I;
if ( creal( y ) != creal( y ) ) {
printf( "unexpected result\n" );
Expand Down
Loading