diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/README.md b/lib/node_modules/@stdlib/math/base/special/hypot/README.md index f7dd7e3239d6..544978fdf947 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/README.md +++ b/lib/node_modules/@stdlib/math/base/special/hypot/README.md @@ -119,20 +119,16 @@ h = hypot( 5.0, NaN ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var hypot = require( '@stdlib/math/base/special/hypot' ); -var x; -var y; -var h; -var i; +var len = 100; +var x = discreteUniform( len, -50, 50 ); +var y = discreteUniform( len, -50, 50 ); -for ( i = 0; i < 100; i++ ) { - x = round( randu()*100.0 ) - 50.0; - y = round( randu()*100.0 ) - 50.0; - h = hypot( x, y ); - console.log( 'h(%d,%d) = %d', x, y, h ); +var i; +for ( i = 0; i < len; i++ ) { + console.log( 'h(%d,%d) = %d', x[ i ], y[ i ], hypot( x[ i ], y[ i ] ) ); } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/benchmark.js index 1ad88a69b8d4..0649d486ad90 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/benchmark.js @@ -21,8 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/array/uniform' ); var pkg = require( './../package.json' ).name; var hypot = require( './../lib' ); @@ -37,16 +37,19 @@ var opts = { // MAIN // bench( pkg, function benchmark( b ) { + var len; var x; var y; var z; var i; + len = 100; + x = uniform( len, -50, 50 ); + y = uniform( len, -50, 50 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100.0 ) - 50.0; - y = ( randu()*100.0 ) - 50.0; - z = hypot( x, y ); + z = hypot( x[ i % len ], y[ i % len ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } @@ -60,16 +63,19 @@ bench( pkg, function benchmark( b ) { }); bench( pkg+'::built-in', opts, function benchmark( b ) { + var len; var x; var y; var z; var i; + len = 100; + x = uniform( len, -50, 50 ); + y = uniform( len, -50, 50 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100.0 ) - 50.0; - y = ( randu()*100.0 ) - 50.0; - z = Math.hypot( x, y ); // eslint-disable-line stdlib/no-builtin-math + z = Math.hypot( x[ i % len ], y[ i % len ] ); // eslint-disable-line stdlib/no-builtin-math if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/benchmark.native.js index a8dfef48eca9..530480ddcdf4 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/hypot/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/array/uniform' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -39,16 +39,19 @@ var opts = { // MAIN // bench( pkg+'::native', opts, function benchmark( b ) { + var len; var x; var y; var z; var i; + len = 100; + x = uniform( len, -50, 50 ); + y = uniform( len, -50, 50 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100.0 ) - 50.0; - y = ( randu()*100.0 ) - 50.0; - z = hypot( x, y ); + z = hypot( x[ i % len ], y[ i % len ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/c/native/benchmark.c index ac9a91e3ddcf..4355b034728e 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/hypot/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() * 100.0 ) - 50.0; + y[ i ] = ( rand_double() * 100.0 ) - 50.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 100.0*rand_double() ) - 50.0; - y = ( 100.0*rand_double() ) - 50.0; - z = stdlib_base_hypot( x, y ); + z = stdlib_base_hypot( 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/hypot/examples/index.js b/lib/node_modules/@stdlib/math/base/special/hypot/examples/index.js index 51bd0803d70e..2a1bff6903b3 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/hypot/examples/index.js @@ -18,18 +18,14 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var hypot = require( './../lib' ); -var x; -var y; -var h; -var i; +var len = 100; +var x = discreteUniform( len, -50, 50 ); +var y = discreteUniform( len, -50, 50 ); -for ( i = 0; i < 100; i++ ) { - x = round( randu()*100.0 ) - 50.0; - y = round( randu()*100.0 ) - 50.0; - h = hypot( x, y ); - console.log( 'h(%d,%d) = %d', x, y, h ); +var i; +for ( i = 0; i < len; i++ ) { + console.log( 'h(%d,%d) = %d', x[ i ], y[ i ], hypot( x[ i ], y[ i ] ) ); } diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/manifest.json b/lib/node_modules/@stdlib/math/base/special/hypot/manifest.json index 33c41d36613f..755db550a9d9 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/hypot/manifest.json @@ -28,7 +28,7 @@ { "task": "build", "src": [ - "./src/hypot.c" + "./src/main.c" ], "include": [ "./include" @@ -41,13 +41,14 @@ "@stdlib/math/base/napi/binary", "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-infinite", - "@stdlib/math/base/special/sqrt" + "@stdlib/math/base/special/sqrt", + "@stdlib/constants/float64/pinf" ] }, { "task": "benchmark", "src": [ - "./src/hypot.c" + "./src/main.c" ], "include": [ "./include" @@ -59,13 +60,14 @@ "dependencies": [ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-infinite", - "@stdlib/math/base/special/sqrt" + "@stdlib/math/base/special/sqrt", + "@stdlib/constants/float64/pinf" ] }, { "task": "examples", "src": [ - "./src/hypot.c" + "./src/main.c" ], "include": [ "./include" @@ -77,7 +79,8 @@ "dependencies": [ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-infinite", - "@stdlib/math/base/special/sqrt" + "@stdlib/math/base/special/sqrt", + "@stdlib/constants/float64/pinf" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/src/hypot.c b/lib/node_modules/@stdlib/math/base/special/hypot/src/main.c similarity index 91% rename from lib/node_modules/@stdlib/math/base/special/hypot/src/hypot.c rename to lib/node_modules/@stdlib/math/base/special/hypot/src/main.c index 58a77e970c42..11ba026d6247 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/src/hypot.c +++ b/lib/node_modules/@stdlib/math/base/special/hypot/src/main.c @@ -20,7 +20,7 @@ #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/assert/is_infinite.h" #include "stdlib/math/base/special/sqrt.h" -#include +#include "stdlib/constants/float64/pinf.h" /** * Computes the hypotenuse avoiding overflow and underflow. @@ -41,7 +41,7 @@ double stdlib_base_hypot( const double x, const double y ) { return 0.0 / 0.0; // NaN } if ( stdlib_base_is_infinite( x ) || stdlib_base_is_infinite( y ) ) { - return HUGE_VAL; + return STDLIB_CONSTANT_FLOAT64_PINF; } a = x; b = y; @@ -60,5 +60,5 @@ double stdlib_base_hypot( const double x, const double y ) { return 0.0; } b /= a; - return a * stdlib_base_sqrt( 1.0 + (b*b) ); + return a * stdlib_base_sqrt( 1.0 + ( b * b ) ); } diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/test/test.js b/lib/node_modules/@stdlib/math/base/special/hypot/test/test.js index 7e88764fab65..122526efbd49 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/hypot/test/test.js @@ -49,28 +49,28 @@ tape( 'the function returns `+infinity` if either argument is `+-infinity`', fun var h; h = hypot( PINF, 3.14 ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( 3.14, PINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( NINF, 3.14 ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( 3.14, NINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( PINF, PINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( NINF, PINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( PINF, NINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( NINF, NINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); t.end(); }); @@ -79,13 +79,13 @@ tape( 'the function returns `NaN` if either argument is `NaN`', function test( t var h; h = hypot( NaN, 3.14 ); - t.strictEqual( isnan( h ), true, 'returns NaN' ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); h = hypot( 3.14, NaN ); - t.strictEqual( isnan( h ), true, 'returns NaN' ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); h = hypot( NaN, NaN ); - t.strictEqual( isnan( h ), true, 'returns NaN' ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); t.end(); }); @@ -94,16 +94,16 @@ tape( 'the function returns `+0` if both arguments are `+-0`', function test( t var h; h = hypot( +0.0, +0.0 ); - t.strictEqual( isPositiveZero( h ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); h = hypot( -0.0, +0.0 ); - t.strictEqual( isPositiveZero( h ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); h = hypot( +0.0, -0.0 ); - t.strictEqual( isPositiveZero( h ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); h = hypot( -0.0, -0.0 ); - t.strictEqual( isPositiveZero( h ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); t.end(); }); @@ -138,13 +138,13 @@ tape( 'the function computes the hypotenuse (canonical inputs)', function test( var h; h = hypot( 3.0, 4.0 ); - t.strictEqual( h, 5.0, 'returns 5.0' ); + t.strictEqual( h, 5.0, 'returns expected value' ); h = hypot( 6.0, 8.0 ); - t.strictEqual( h, 10.0, 'returns 10.0' ); + t.strictEqual( h, 10.0, 'returns expected value' ); h = hypot( 5.0, 12.0 ); - t.strictEqual( h, 13.0, 'returns 13.0' ); + t.strictEqual( h, 13.0, 'returns expected value' ); t.end(); }); @@ -153,7 +153,7 @@ tape( 'the function avoids overflow', function test( t ) { var h; h = sqrt( pow( 1.0e308, 2 ) + pow( 1.0e308, 2 ) ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( 1.0e308, 1.0e308 ); t.strictEqual( h, 1.4142135623730951e308, 'avoids overflow' ); diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/hypot/test/test.native.js index 24d1c02f6219..575e0db62023 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/hypot/test/test.native.js @@ -58,28 +58,28 @@ tape( 'the function returns `+infinity` if either argument is `+-infinity`', opt var h; h = hypot( PINF, 3.14 ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( 3.14, PINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( NINF, 3.14 ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( 3.14, NINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( PINF, PINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( NINF, PINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( PINF, NINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( NINF, NINF ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); t.end(); }); @@ -88,13 +88,13 @@ tape( 'the function returns `NaN` if either argument is `NaN`', opts, function t var h; h = hypot( NaN, 3.14 ); - t.strictEqual( isnan( h ), true, 'returns NaN' ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); h = hypot( 3.14, NaN ); - t.strictEqual( isnan( h ), true, 'returns NaN' ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); h = hypot( NaN, NaN ); - t.strictEqual( isnan( h ), true, 'returns NaN' ); + t.strictEqual( isnan( h ), true, 'returns expected value' ); t.end(); }); @@ -103,16 +103,16 @@ tape( 'the function returns `+0` if both arguments are `+-0`', opts, function te var h; h = hypot( +0.0, +0.0 ); - t.strictEqual( isPositiveZero( h ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); h = hypot( -0.0, +0.0 ); - t.strictEqual( isPositiveZero( h ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); h = hypot( +0.0, -0.0 ); - t.strictEqual( isPositiveZero( h ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); h = hypot( -0.0, -0.0 ); - t.strictEqual( isPositiveZero( h ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( h ), true, 'returns expected value' ); t.end(); }); @@ -147,13 +147,13 @@ tape( 'the function computes the hypotenuse (canonical inputs)', opts, function var h; h = hypot( 3.0, 4.0 ); - t.strictEqual( h, 5.0, 'returns 5.0' ); + t.strictEqual( h, 5.0, 'returns expected value' ); h = hypot( 6.0, 8.0 ); - t.strictEqual( h, 10.0, 'returns 10.0' ); + t.strictEqual( h, 10.0, 'returns expected value' ); h = hypot( 5.0, 12.0 ); - t.strictEqual( h, 13.0, 'returns 13.0' ); + t.strictEqual( h, 13.0, 'returns expected value' ); t.end(); }); @@ -162,7 +162,7 @@ tape( 'the function avoids overflow', opts, function test( t ) { var h; h = sqrt( pow( 1.0e308, 2 ) + pow( 1.0e308, 2 ) ); - t.strictEqual( h, PINF, 'returns +infinity' ); + t.strictEqual( h, PINF, 'returns expected value' ); h = hypot( 1.0e308, 1.0e308 ); t.strictEqual( h, 1.4142135623730951e308, 'avoids overflow' );