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 544978fdf947..b1ee93e658d8 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/README.md +++ b/lib/node_modules/@stdlib/math/base/special/hypot/README.md @@ -52,7 +52,7 @@ h = hypot( -0.0, -0.0 ); // returns +0.0 ``` -If either argument is `NaN`, the function returns `NaN`. +If either argument is `NaN` and the other argument is not `+-Infinity`, the function returns `NaN`. ```javascript var h = hypot( NaN, 12.0 ); diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/hypot/docs/repl.txt index 72d654bbef5e..5fc64857cba2 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/hypot/docs/repl.txt @@ -2,7 +2,8 @@ {{alias}}( x, y ) Computes the hypotenuse avoiding overflow and underflow. - If either argument is `NaN`, the function returns `NaN`. + If either argument is `NaN` and the other argument is not `+-Infinity`, + the function returns `NaN`. Parameters ---------- diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/lib/main.js b/lib/node_modules/@stdlib/math/base/special/hypot/lib/main.js index d64a8420dfdb..a5b69e372bed 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/hypot/lib/main.js @@ -49,12 +49,14 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' ); */ function hypot( x, y ) { var tmp; - if ( isnan( x ) || isnan( y ) ) { - return NaN; - } + + // If one of the arguments is `+-infinity`, return `+infinity` even if the other argument is `NaN` (IEEE 754-2019)... if ( isInfinite( x ) || isInfinite( y ) ) { return PINF; } + if ( isnan( x ) || isnan( y ) ) { + return NaN; + } if ( x < 0.0 ) { x = -x; } diff --git a/lib/node_modules/@stdlib/math/base/special/hypot/src/main.c b/lib/node_modules/@stdlib/math/base/special/hypot/src/main.c index 11ba026d6247..f4c40fd94752 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypot/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/hypot/src/main.c @@ -37,12 +37,14 @@ double stdlib_base_hypot( const double x, const double y ) { double tmp; double a; double b; - if ( stdlib_base_is_nan( x ) || stdlib_base_is_nan( y ) ) { - return 0.0 / 0.0; // NaN - } + + // If one of the arguments is `+-infinity`, return `+infinity` even if the other argument is `NaN` (IEEE 754-2019)... if ( stdlib_base_is_infinite( x ) || stdlib_base_is_infinite( y ) ) { return STDLIB_CONSTANT_FLOAT64_PINF; } + if ( stdlib_base_is_nan( x ) || stdlib_base_is_nan( y ) ) { + return 0.0 / 0.0; // NaN + } a = x; b = y; if ( a < 0.0 ) { 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 122526efbd49..f40cac2b6e61 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 @@ -72,10 +72,22 @@ tape( 'the function returns `+infinity` if either argument is `+-infinity`', fun h = hypot( NINF, NINF ); t.strictEqual( h, PINF, 'returns expected value' ); + h = hypot( NaN, PINF ); + t.strictEqual( h, PINF, 'returns expected value' ); + + h = hypot( PINF, NaN ); + t.strictEqual( h, PINF, 'returns expected value' ); + + h = hypot( NINF, NaN ); + t.strictEqual( h, PINF, 'returns expected value' ); + + h = hypot( NaN, NINF ); + t.strictEqual( h, PINF, 'returns expected value' ); + t.end(); }); -tape( 'the function returns `NaN` if either argument is `NaN`', function test( t ) { +tape( 'the function returns `NaN` if either argument is `NaN` but not `+-infinity`', function test( t ) { var h; h = hypot( NaN, 3.14 ); 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 575e0db62023..fcdc958e4a94 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 @@ -81,10 +81,22 @@ tape( 'the function returns `+infinity` if either argument is `+-infinity`', opt h = hypot( NINF, NINF ); t.strictEqual( h, PINF, 'returns expected value' ); + h = hypot( NaN, PINF ); + t.strictEqual( h, PINF, 'returns expected value' ); + + h = hypot( PINF, NaN ); + t.strictEqual( h, PINF, 'returns expected value' ); + + h = hypot( NINF, NaN ); + t.strictEqual( h, PINF, 'returns expected value' ); + + h = hypot( NaN, NINF ); + t.strictEqual( h, PINF, 'returns expected value' ); + t.end(); }); -tape( 'the function returns `NaN` if either argument is `NaN`', opts, function test( t ) { +tape( 'the function returns `NaN` if either argument is `NaN` but not `+-infinity`', opts, function test( t ) { var h; h = hypot( NaN, 3.14 );