diff --git a/lib/node_modules/@stdlib/math/base/special/pow/lib/main.js b/lib/node_modules/@stdlib/math/base/special/pow/lib/main.js index 69e5d6216a6b..0b194ea6f8f1 100644 --- a/lib/node_modules/@stdlib/math/base/special/pow/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/pow/lib/main.js @@ -229,10 +229,10 @@ function pow( x, y ) { if ( y === -1.0 ) { return 1.0 / x; } - if ( y === 0.5 ) { + if ( y === 0.5 && x > 0.0 ) { return sqrt( x ); } - if ( y === -0.5 ) { + if ( y === -0.5 && x > 0.0 ) { return 1.0 / sqrt( x ); } if ( y === 2.0 ) { @@ -256,7 +256,7 @@ function pow( x, y ) { // Special cases `x`... if ( lx === 0 ) { - if ( hx === 0 ) { + if ( ( hx & ABS_MASK ) === 0 ) { return xIsZero( x, y ); } if ( x === 1.0 ) { diff --git a/lib/node_modules/@stdlib/math/base/special/pow/src/main.c b/lib/node_modules/@stdlib/math/base/special/pow/src/main.c index b6a131f614fa..3b60722a4198 100644 --- a/lib/node_modules/@stdlib/math/base/special/pow/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/pow/src/main.c @@ -587,10 +587,10 @@ double stdlib_base_pow( const double x, const double y ) { if ( y == -1.0 ) { return 1.0 / xc; } - if ( y == 0.5 ) { + if ( y == 0.5 && xc > 0.0 ) { return stdlib_base_sqrt( xc ); } - if ( y == -0.5 ) { + if ( y == -0.5 && xc > 0.0 ) { return 1.0 / stdlib_base_sqrt( xc ); } if ( y == 2.0 ) { @@ -612,7 +612,7 @@ double stdlib_base_pow( const double x, const double y ) { // Special cases `x`... if ( lx == 0 ) { - if ( hx == 0 ) { + if ( ( hx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) == 0 ) { return x_is_zero( xc, y ); } if ( xc == 1.0 ) { diff --git a/lib/node_modules/@stdlib/math/base/special/pow/test/test.js b/lib/node_modules/@stdlib/math/base/special/pow/test/test.js index 8e196a8addf1..ca6ce3d946c7 100644 --- a/lib/node_modules/@stdlib/math/base/special/pow/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/pow/test/test.js @@ -605,6 +605,20 @@ tape( '`-1` raised to any odd integer is `-1`', function test( t ) { t.end(); }); +tape( '`-0` and `-infinity` raised to a non-integer power return `+0` or `+infinity`', function test( t ) { + var y; + var i; + + y = [ 0.5, 0.25, 2.5 ]; + for ( i = 0; i < y.length; i++ ) { + t.strictEqual( isPositiveZero( pow( -0.0, y[ i ] ) ), true, 'returns expected value' ); + t.strictEqual( pow( -0.0, -y[ i ] ), PINF, 'returns expected value' ); + t.strictEqual( pow( NINF, y[ i ] ), PINF, 'returns expected value' ); + t.strictEqual( isPositiveZero( pow( NINF, -y[ i ] ) ), true, 'returns expected value' ); + } + t.end(); +}); + tape( '`+-0` raised to `-infinity` is `+infinity`', function test( t ) { var v; diff --git a/lib/node_modules/@stdlib/math/base/special/pow/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/pow/test/test.native.js index 77da65e94d9b..ab813d462150 100644 --- a/lib/node_modules/@stdlib/math/base/special/pow/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/pow/test/test.native.js @@ -628,6 +628,20 @@ tape( '`-1` raised to any odd integer is `-1`', opts, function test( t ) { t.end(); }); +tape( '`-0` and `-infinity` raised to a non-integer power return `+0` or `+infinity`', opts, function test( t ) { + var y; + var i; + + y = [ 0.5, 0.25, 2.5 ]; + for ( i = 0; i < y.length; i++ ) { + t.strictEqual( isPositiveZero( pow( -0.0, y[ i ] ) ), true, 'returns expected value' ); + t.strictEqual( pow( -0.0, -y[ i ] ), PINF, 'returns expected value' ); + t.strictEqual( pow( NINF, y[ i ] ), PINF, 'returns expected value' ); + t.strictEqual( isPositiveZero( pow( NINF, -y[ i ] ) ), true, 'returns expected value' ); + } + t.end(); +}); + tape( '`+-0` raised to `-infinity` is `+infinity`', opts, function test( t ) { var v; diff --git a/lib/node_modules/@stdlib/math/base/special/powf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/powf/lib/main.js index 4f9dafe1b1ef..a27aab29a749 100644 --- a/lib/node_modules/@stdlib/math/base/special/powf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/powf/lib/main.js @@ -170,10 +170,10 @@ function powf( x, y ) { if ( y === NEG_ONE ) { return f32( ONE / x ); } - if ( y === HALF ) { + if ( y === HALF && x > ZERO ) { return sqrtf( x ); } - if ( y === NEG_HALF ) { + if ( y === NEG_HALF && x > ZERO ) { return f32( ONE / sqrtf( x ) ); } if ( y === TWO ) { diff --git a/lib/node_modules/@stdlib/math/base/special/powf/src/main.c b/lib/node_modules/@stdlib/math/base/special/powf/src/main.c index 19033d983de7..c16b979a96a5 100644 --- a/lib/node_modules/@stdlib/math/base/special/powf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/powf/src/main.c @@ -532,10 +532,10 @@ float stdlib_base_powf( const float x, const float y ) { if ( y == -1.0f ) { return 1.0f / x; } - if ( y == 0.5f ) { + if ( y == 0.5f && x > 0.0f ) { return stdlib_base_sqrtf( x ); } - if ( y == -0.5f ) { + if ( y == -0.5f && x > 0.0f ) { return 1.0f / stdlib_base_sqrtf( x ); } if ( y == 2.0f ) { diff --git a/lib/node_modules/@stdlib/math/base/special/powf/test/test.js b/lib/node_modules/@stdlib/math/base/special/powf/test/test.js index 998da6f7a1a9..60281f022062 100644 --- a/lib/node_modules/@stdlib/math/base/special/powf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/powf/test/test.js @@ -689,6 +689,20 @@ tape( '`-1` raised to any odd integer is `-1`', function test( t ) { t.end(); }); +tape( '`-0` and `-infinity` raised to a non-integer power return `+0` or `+infinity`', function test( t ) { + var y; + var i; + + y = [ 0.5, 0.25, 2.5 ]; + for ( i = 0; i < y.length; i++ ) { + t.strictEqual( isPositiveZerof( powf( -0.0, y[ i ] ) ), true, 'returns expected value' ); + t.strictEqual( powf( -0.0, -y[ i ] ), PINF, 'returns expected value' ); + t.strictEqual( powf( NINF, y[ i ] ), PINF, 'returns expected value' ); + t.strictEqual( isPositiveZerof( powf( NINF, -y[ i ] ) ), true, 'returns expected value' ); + } + t.end(); +}); + tape( '`+-0` raised to `-infinity` is `+infinity`', function test( t ) { var v; diff --git a/lib/node_modules/@stdlib/math/base/special/powf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/powf/test/test.native.js index 1402f8f4e28d..b3b34a2f50f6 100644 --- a/lib/node_modules/@stdlib/math/base/special/powf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/powf/test/test.native.js @@ -698,6 +698,20 @@ tape( '`-1` raised to any odd integer is `-1`', opts, function test( t ) { t.end(); }); +tape( '`-0` and `-infinity` raised to a non-integer power return `+0` or `+infinity`', opts, function test( t ) { + var y; + var i; + + y = [ 0.5, 0.25, 2.5 ]; + for ( i = 0; i < y.length; i++ ) { + t.strictEqual( isPositiveZerof( powf( -0.0, y[ i ] ) ), true, 'returns expected value' ); + t.strictEqual( powf( -0.0, -y[ i ] ), PINF, 'returns expected value' ); + t.strictEqual( powf( NINF, y[ i ] ), PINF, 'returns expected value' ); + t.strictEqual( isPositiveZerof( powf( NINF, -y[ i ] ) ), true, 'returns expected value' ); + } + t.end(); +}); + tape( '`+-0` raised to `-infinity` is `+infinity`', opts, function test( t ) { var v;