diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/README.md b/lib/node_modules/@stdlib/math/base/special/ldexp/README.md index d2b8a7180e0c..bf5cb28c57e3 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/README.md +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/README.md @@ -182,44 +182,19 @@ double stdlib_base_ldexp( const double frac, const int32_t exp ); ```c #include "stdlib/math/base/special/ldexp.h" -#include "stdlib/math/base/special/frexp.h" -#include #include #include -#include -#include - -static double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} int main( void ) { - double sign; - double frac; - int32_t exp; - double x; - double v; + double y; int i; - for ( i = 0; i < 100; i++ ) { - if ( rand_double() < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - // Generate a random number: - frac = rand_double() * 10.0; - exp = (int32_t)( rand_double()*616.0 ) - 308; - x = sign * frac * pow( 10.0, exp ); - - // Break the number into a normalized fraction and an integer power of two: - stdlib_base_frexp( x, &frac, &exp ); - - // Reconstitute the original number: - v = stdlib_base_ldexp( frac, exp ); + const double frac[] = { 0.5, 5.0, 0.0, 3.5, 7.9 }; + const int32_t exp[] = { 3, -2, 20, 39, 14 }; - printf( "%e = %lf * 2^%" PRId32 " = %e\n", x, frac, exp, v ); + for ( i = 0; i < 5; i++ ) { + y = stdlib_base_ldexp( frac[ i ], exp[ i ] ); + printf( "ldexp(%lf, %d) = %lf\n", frac[ i ], exp[ i ], y ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/benchmark.js index 936f7b454a9f..4ba690a4863b 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/benchmark.js @@ -21,8 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var ldexp = require( './../lib' ); @@ -36,11 +36,12 @@ bench( pkg, function benchmark( b ) { var z; var i; + x = uniform( 100, -10.0, 10.0 ); + y = discreteUniform( 100, -1020.0, 1020.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*20.0 ) - 10.0; - y = round( randu()*2040.0 ) - 1020.0; - z = ldexp( x, y ); + z = ldexp( x[ i % x.length ], y[ i % y.length ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/benchmark.native.js index e6e30afbeeea..b2aa12a99469 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/benchmark.native.js @@ -22,8 +22,8 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -45,11 +45,12 @@ bench( pkg+'::native', opts, function benchmark( b ) { var z; var i; + x = uniform( 100, -10.0, 10.0 ); + y = discreteUniform( 100, -1020.0, 1020.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*20.0 ) - 10.0; - y = round( randu()*2040.0 ) - 1020.0; - z = ldexp( x, y ); + z = ldexp( x[ i % x.length ], y[ i % y.length ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/benchmark.c index c07fc45d9886..7da27dd79633 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/benchmark.c @@ -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 ] = ( rand_double() * 20.0 ) - 10.0; + y[ i ] = ( rand_double() * 2048.0 ) - 1024.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double()*20.0 ) - 10.0; - y = ( rand_double()*2048.0 ) - 1024.0; - z = ldexp( x, y ); + z = ldexp( x[ i % 100 ], y[ i % 100 ] ); if ( z != z ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/cephes/benchmark.c index f85b2f85c03b..084dc4fd0f4b 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/cephes/benchmark.c @@ -95,17 +95,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 ] = ( rand_double() * 20.0 ) - 10.0; + y[ i ] = ( rand_double() * 2048.0 ) - 1024.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double()*20.0 ) - 10.0; - y = ( rand_double()*2048.0 ) - 1024.0; - z = ldexp( x, y ); + z = ldexp( x[ i % 100 ], y[ i % 100 ] ); if ( z != z ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/native/benchmark.c index d6b9724305ad..ff5d6ddf7ffc 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/c/native/benchmark.c @@ -91,17 +91,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 ] = ( rand_double() * 20.0 ) - 10.0; + y[ i ] = ( rand_double() * 2048.0 ) - 1024.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double()*20.0 ) - 10.0; - y = ( rand_double()*2048.0 ) - 1024.0; - z = stdlib_base_ldexp( x, y ); + z = stdlib_base_ldexp( x[ i % 100 ], y[ i % 100 ] ); if ( z != z ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/cpp/benchmark.cpp b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/cpp/benchmark.cpp index 0e8de32b97e0..de40f7eb68ce 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/cpp/benchmark.cpp +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/benchmark/cpp/benchmark.cpp @@ -93,17 +93,20 @@ double rand_double() { */ double benchmark() { 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 ] = ( rand_double() * 20.0 ) - 10.0; + y[ i ] = ( rand_double() * 2048.0 ) - 1024.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double()*20.0 ) - 10.0; - y = ( rand_double()*2048.0 ) - 1024.0; - z = ldexp( x, y ); + z = ldexp( x[ i % 100 ], y[ i % 100 ] ); if ( z != z ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/ldexp/examples/c/example.c index b24357093432..1aa206db30eb 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/examples/c/example.c @@ -16,47 +16,19 @@ * limitations under the License. */ - #include "stdlib/math/base/special/ldexp.h" -#include "stdlib/math/base/special/frexp.h" -#include #include #include -#include -#include - -// TODO: replace use of `pow` with stdlib_base_pow() - -static double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} int main( void ) { - double sign; - double frac; - int32_t exp; - double x; - double v; - int i; - - for ( i = 0; i < 100; i++ ) { - if ( rand_double() < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - // Generate a random number: - frac = rand_double() * 10.0; - exp = (int32_t)( rand_double()*616.0 ) - 308; - x = sign * frac * pow( 10.0, exp ); - - // Break the number into a normalized fraction and an integer power of two: - stdlib_base_frexp( x, &frac, &exp ); + double y; + int i; - // Reconstitute the original number: - v = stdlib_base_ldexp( frac, exp ); + const double frac[] = { 0.5, 5.0, 0.0, 3.5, 7.9 }; + const int32_t exp[] = { 3, -2, 20, 39, 14 }; - printf( "%e = %lf * 2^%" PRId32 " = %e\n", x, frac, exp, v ); - } + for ( i = 0; i < 5; i++ ) { + y = stdlib_base_ldexp( frac[ i ], exp[ i ] ); + printf( "ldexp(%lf, %d) = %lf\n", frac[ i ], exp[ i ], y ); + } } diff --git a/lib/node_modules/@stdlib/math/base/special/ldexp/manifest.json b/lib/node_modules/@stdlib/math/base/special/ldexp/manifest.json index 6ecdff858d77..a3c204ec1186 100644 --- a/lib/node_modules/@stdlib/math/base/special/ldexp/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/ldexp/manifest.json @@ -81,8 +81,7 @@ "@stdlib/constants/float64/min-base2-exponent-subnormal", "@stdlib/constants/float64/max-base2-exponent", "@stdlib/constants/float64/max-base2-exponent-subnormal", - "@stdlib/constants/float64/exponent-bias", - "@stdlib/math/base/special/frexp" + "@stdlib/constants/float64/exponent-bias" ] }, {