diff --git a/lib/node_modules/@stdlib/number/float32/base/add/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/add/benchmark/c/benchmark.c index feb7c2f55b15..8b76200edaf7 100644 --- a/lib/node_modules/@stdlib/number/float32/base/add/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/add/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -100,14 +102,17 @@ float addf( const float x, const float y ) { static double benchmark( void ) { double elapsed; double t; - float x; + float *x; float y; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = addf( x, 5.0f ); + y = addf( x[ i%100 ], 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/add/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/add/benchmark/c/native/benchmark.c index 3b39cdc9375d..7f8cd6b38f16 100644 --- a/lib/node_modules/@stdlib/number/float32/base/add/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/add/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -92,14 +94,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float *x; float y; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = stdlib_base_float32_add( x, 5.0f ); + y = stdlib_base_float32_add( x[ i%100 ], 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/div/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/div/benchmark/c/benchmark.c index d1455d2a7521..181be49f332c 100644 --- a/lib/node_modules/@stdlib/number/float32/base/div/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/div/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -100,14 +102,17 @@ float divide( const float x, const float y ) { static double benchmark( void ) { double elapsed; double t; - float x; + float *x; float y; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = divide( x, 5.0f ); + y = divide( x[ i%100 ], 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/div/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/div/benchmark/c/native/benchmark.c index 1c7e254f6880..c67f71b9bf71 100644 --- a/lib/node_modules/@stdlib/number/float32/base/div/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/div/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -92,14 +94,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float *x; float y; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = stdlib_base_float32_div( x, 5.0f ); + y = stdlib_base_float32_div( x[ i%100 ], 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/exponent/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/exponent/benchmark/c/benchmark.c index 613db393871b..f807b5a8a28c 100644 --- a/lib/node_modules/@stdlib/number/float32/base/exponent/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/exponent/benchmark/c/benchmark.c @@ -76,13 +76,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -94,13 +96,16 @@ static double benchmark( void ) { double elapsed; int32_t out; double t; - float x; + float *x; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -5.0e6f, 5.0e6f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_float()*1.0e7f ) - 5.0e6f; - out = stdlib_base_float32_exponent( x ); + out = stdlib_base_float32_exponent( x[ i%100 ] ); if ( out == 128 ) { printf( "unexpected result\n" ); break; @@ -110,6 +115,7 @@ static double benchmark( void ) { if ( out == 128 ) { printf( "unexpected result\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/identity/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/identity/benchmark/c/native/benchmark.c index 4fb6e04bc3fc..0c7679caa527 100644 --- a/lib/node_modules/@stdlib/number/float32/base/identity/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/identity/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -92,14 +94,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float *x; float y; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = stdlib_base_float32_identity( x ); + y = stdlib_base_float32_identity( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/mul/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/mul/benchmark/c/benchmark.c index f1c610218989..34fb599a0be9 100644 --- a/lib/node_modules/@stdlib/number/float32/base/mul/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/mul/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -99,15 +101,18 @@ float mulf( const float x, const float y ) { */ static double benchmark( void ) { double elapsed; - float x; + float *x; float y; double t; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = mulf( x, 5.0f ); + y = mulf( x[ i%100 ], 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/mul/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/mul/benchmark/c/native/benchmark.c index 3bc81530875c..34728539232c 100644 --- a/lib/node_modules/@stdlib/number/float32/base/mul/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/mul/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -91,15 +93,18 @@ static float rand_float( void ) { */ static double benchmark( void ) { double elapsed; - float x; + float *x; float y; double t; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = stdlib_base_float32_mul( x, 5.0f ); + y = stdlib_base_float32_mul( x[ i%100 ], 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/normalize/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/normalize/benchmark/c/benchmark.c index e10923c918c6..4a7da20d1969 100644 --- a/lib/node_modules/@stdlib/number/float32/base/normalize/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/normalize/benchmark/c/benchmark.c @@ -76,13 +76,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -93,16 +95,20 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; int32_t exp; - float x; + float *x; float y; int i; srand( time( NULL ) ); + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -5.0e6f, 5.0e6f ); + } + elapsed = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_float()*1.0e7f ) - 5.0e6f; - stdlib_base_float32_normalize( x, &y, &exp ); + stdlib_base_float32_normalize( x[ i%100 ], &y, &exp ); if ( y != y || exp < 0 ) { printf( "unexpected results\n" ); } @@ -111,6 +117,7 @@ static double benchmark( void ) { if ( y != y || exp < 0 ) { printf( "unexpected results\n" ); } + free( x ); return elapsed; } /** diff --git a/lib/node_modules/@stdlib/number/float32/base/signbit/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/signbit/benchmark/c/benchmark.c index b552e4c7f17e..ad22586fe207 100644 --- a/lib/node_modules/@stdlib/number/float32/base/signbit/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/signbit/benchmark/c/benchmark.c @@ -76,13 +76,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -94,13 +96,16 @@ static double benchmark( void ) { double elapsed; int8_t out; double t; - float x; + float *x; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -100.0f, 100.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_float()*200.0f ) - 100.0f; - out = stdlib_base_float32_signbit( x ); + out = stdlib_base_float32_signbit( x[ i%100 ] ); if ( out != 0 && out != 1 ) { printf( "unexpected result\n" ); break; @@ -110,6 +115,7 @@ static double benchmark( void ) { if ( out != 0 && out != 1 ) { printf( "unexpected result\n" ); } + free( x ); return elapsed; } /** diff --git a/lib/node_modules/@stdlib/number/float32/base/significand/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/significand/benchmark/c/benchmark.c index 80ce205e3d61..1101afd026a5 100644 --- a/lib/node_modules/@stdlib/number/float32/base/significand/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/significand/benchmark/c/benchmark.c @@ -76,13 +76,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -94,13 +96,16 @@ static double benchmark( void ) { double elapsed; int32_t out; double t; - float x; + float *x; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -5.0e6f, 5.0e6f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_float()*1.0e7f ) - 5.0e6f; - out = stdlib_base_float32_significand( x ); + out = stdlib_base_float32_significand( x[ i%100 ] ); if ( out < 0 ) { printf( "unexpected result\n" ); break; @@ -110,6 +115,7 @@ static double benchmark( void ) { if ( out < 0 ) { printf( "unexpected result\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/sub/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/sub/benchmark/c/benchmark.c index e0f123401152..a8cecee06d1f 100644 --- a/lib/node_modules/@stdlib/number/float32/base/sub/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/sub/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -100,14 +102,17 @@ float subf( const float x, const float y ) { static double benchmark( void ) { double elapsed; double t; - float x; + float *x; float y; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = subf( x, 5.0f ); + y = subf( x[ i%100 ], 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float32/base/sub/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float32/base/sub/benchmark/c/native/benchmark.c index a6a46838a66f..c63aa8a89178 100644 --- a/lib/node_modules/@stdlib/number/float32/base/sub/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float32/base/sub/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*( max-min ) ); } /** @@ -92,14 +94,17 @@ static float rand_float( void ) { static double benchmark( void ) { double elapsed; double t; - float x; + float *x; float y; int i; + x = (float *) malloc( 100 * sizeof( float ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0f, 500.0f ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0f*rand_float() ) - 500.0f; - y = stdlib_base_float32_sub( x, 5.0f ); + y = stdlib_base_float32_sub( x[ i%100 ], 5.0f ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/add3/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/add3/benchmark/c/benchmark.c index 8d9f7e05e93d..a13fcd7a0193 100644 --- a/lib/node_modules/@stdlib/number/float64/base/add3/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/add3/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -99,15 +101,18 @@ double add3( const double x, const double y, const double z ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = add3( x, 5.0, 2.0 ); + y = add3( x[ i%100 ], 5.0, 2.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/add3/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/add3/benchmark/c/native/benchmark.c index b1d4fff218c7..a632bfa7c924 100644 --- a/lib/node_modules/@stdlib/number/float64/base/add3/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/add3/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -91,15 +93,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = stdlib_base_float64_add3( x, 5.0, 2.0 ); + y = stdlib_base_float64_add3( x[ i%100 ], 5.0, 2.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/add4/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/add4/benchmark/c/benchmark.c index f1f70ba96182..7667f5e380f3 100644 --- a/lib/node_modules/@stdlib/number/float64/base/add4/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/add4/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -99,15 +101,18 @@ double add4( const double x, const double y, const double z, const double w ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = add4( x, 5.0, 2.0, x ); + y = add4( x[ i%100 ], 5.0, 2.0, x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/add4/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/add4/benchmark/c/native/benchmark.c index 3cc67510b2d2..4964372df35e 100644 --- a/lib/node_modules/@stdlib/number/float64/base/add4/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/add4/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -91,15 +93,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = stdlib_base_float64_add4( x, 5.0, 2.0, x ); + y = stdlib_base_float64_add4( x[ i%100 ], 5.0, 2.0, x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/add5/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/add5/benchmark/c/benchmark.c index e0fa133210b8..9069d3c33a63 100644 --- a/lib/node_modules/@stdlib/number/float64/base/add5/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/add5/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -99,15 +101,18 @@ double add5( const double x, const double y, const double z, const double w, con */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = add5( x, 5.0, 2.0, x, x+1.0 ); + y = add5( x[ i%100 ], 5.0, 2.0, x[ i%100 ], x[ i%100 ]+1.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/add5/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/add5/benchmark/c/native/benchmark.c index f8ca11fa3305..7213d31095db 100644 --- a/lib/node_modules/@stdlib/number/float64/base/add5/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/add5/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -91,15 +93,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = stdlib_base_float64_add5( x, 5.0, 2.0, x, x+1.0 ); + y = stdlib_base_float64_add5( x[ i%100 ], 5.0, 2.0, x[ i%100 ], x[ i%100 ]+1.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/div/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/div/benchmark/c/benchmark.c index 965eafddb238..8a92ac5dde4c 100644 --- a/lib/node_modules/@stdlib/number/float64/base/div/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/div/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -99,15 +101,18 @@ double divide( const double x, const double y ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = divide( x, 5.0 ); + y = divide( x[ i%100 ], 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/div/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/div/benchmark/c/native/benchmark.c index 82b2c9deef20..35cc5893f5b5 100644 --- a/lib/node_modules/@stdlib/number/float64/base/div/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/div/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -91,15 +93,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = stdlib_base_float64_div( x, 5.0 ); + y = stdlib_base_float64_div( x[ i%100 ], 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/exponent/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/exponent/benchmark/c/benchmark.c index 8b1cdb3069c5..56dc1c033530 100644 --- a/lib/node_modules/@stdlib/number/float64/base/exponent/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/exponent/benchmark/c/benchmark.c @@ -76,13 +76,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -93,14 +95,17 @@ static double rand_double( void ) { static double benchmark( void ) { double elapsed; int32_t out; - double x; + double *x; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -5.0e6, 5.0e6 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double()*1.0e7 ) - 5.0e6; - out = stdlib_base_float64_exponent( x ); + out = stdlib_base_float64_exponent( x[ i%100 ] ); if ( out == 1024 ) { printf( "unexpected result\n" ); break; @@ -110,6 +115,7 @@ static double benchmark( void ) { if ( out == 1024 ) { printf( "unexpected result\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/identity/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/identity/benchmark/c/native/benchmark.c index ed27430f2877..e27c28d056ff 100644 --- a/lib/node_modules/@stdlib/number/float64/base/identity/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/identity/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -91,15 +93,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = stdlib_base_float64_identity( x ); + y = stdlib_base_float64_identity( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/mul/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/mul/benchmark/c/benchmark.c index 34d88e21d0e6..0121af7bbd1b 100644 --- a/lib/node_modules/@stdlib/number/float64/base/mul/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/mul/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -99,15 +101,18 @@ double mul( const double x, const double y ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = mul( x, 5.0 ); + y = mul( x[ i%100 ], 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +122,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/mul/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/mul/benchmark/c/native/benchmark.c index 73e33ba977f7..e91d8fb54455 100644 --- a/lib/node_modules/@stdlib/number/float64/base/mul/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/mul/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -91,15 +93,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = stdlib_base_float64_mul( x, 5.0 ); + y = stdlib_base_float64_mul( x[ i%100 ], 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/normalize/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/normalize/benchmark/c/benchmark.c index 17445abd8cb3..376399db2349 100644 --- a/lib/node_modules/@stdlib/number/float64/base/normalize/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/normalize/benchmark/c/benchmark.c @@ -76,13 +76,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -93,16 +95,20 @@ static double rand_double( void ) { static double benchmark( void ) { double elapsed; int32_t exp; - double x; + double *x; double y; int i; srand( time( NULL ) ); + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -5.0e6, 5.0e6 ); + } + elapsed = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double()*1.0e7 ) - 5.0e6; - stdlib_base_float64_normalize( x, &y, &exp ); + stdlib_base_float64_normalize( x[ i%100 ], &y, &exp ); if ( y != y || exp != exp ) { printf( "unexpected results\n" ); } @@ -111,6 +117,7 @@ static double benchmark( void ) { if ( y != y || exp != exp ) { printf( "unexpected results\n" ); } + free( x ); return elapsed; } /** diff --git a/lib/node_modules/@stdlib/number/float64/base/sub/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/sub/benchmark/c/benchmark.c index 5460d403e958..d1a73612e83f 100644 --- a/lib/node_modules/@stdlib/number/float64/base/sub/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/sub/benchmark/c/benchmark.c @@ -74,13 +74,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -99,15 +101,19 @@ double sub( const double x, const double y ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = sub( x, 5.0 ); + y = sub( x[ i%100 ], 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -117,6 +123,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; } diff --git a/lib/node_modules/@stdlib/number/float64/base/sub/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/number/float64/base/sub/benchmark/c/native/benchmark.c index b937ac8af5c7..0282e70d3d37 100644 --- a/lib/node_modules/@stdlib/number/float64/base/sub/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/number/float64/base/sub/benchmark/c/native/benchmark.c @@ -75,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*( max-min ) ); } /** @@ -91,15 +93,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double *x; double y; double t; int i; + x = (double *) malloc( 100 * sizeof( double ) ); + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( -500.0, 500.0 ); + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = stdlib_base_float64_sub( x, 5.0 ); + y = stdlib_base_float64_sub( x[ i%100 ], 5.0 ); if ( y != y ) { printf( "should not return NaN\n" ); break; @@ -109,6 +114,7 @@ static double benchmark( void ) { if ( y != y ) { printf( "should not return NaN\n" ); } + free( x ); return elapsed; }