diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/lib/main.js b/lib/node_modules/@stdlib/math/base/assert/is-odd/lib/main.js index e4d7fedc7068..330210a26dad 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-odd/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/lib/main.js @@ -21,6 +21,9 @@ // MODULES // var isEven = require( '@stdlib/math/base/assert/is-even' ); +var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); // MAIN // @@ -48,6 +51,13 @@ var isEven = require( '@stdlib/math/base/assert/is-even' ); * // returns false */ function isOdd( x ) { + // Every finite value whose magnitude exceeds the maximum safe integer is even, but `x-1` and `x+1` would round to an even value... + if ( x > MAX_SAFE_INTEGER ) { + return ( x === PINF ); + } + if ( x < -MAX_SAFE_INTEGER ) { + return ( x === NINF ); + } // Check sign to prevent overflow... if ( x > 0.0 ) { return isEven( x-1.0 ); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/manifest.json b/lib/node_modules/@stdlib/math/base/assert/is-odd/manifest.json index f70657b50ed3..aed6890e7cc4 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-odd/manifest.json +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/manifest.json @@ -42,7 +42,10 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-double", - "@stdlib/napi/create-int32" + "@stdlib/napi/create-int32", + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf" ] }, { @@ -58,7 +61,10 @@ ], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-even" + "@stdlib/math/base/assert/is-even", + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf" ] }, { @@ -72,7 +78,10 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-even" + "@stdlib/math/base/assert/is-even", + "@stdlib/constants/float64/max-safe-integer", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/src/main.c b/lib/node_modules/@stdlib/math/base/assert/is-odd/src/main.c index 9218fecbaaa7..d91b36155063 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-odd/src/main.c +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/src/main.c @@ -18,6 +18,9 @@ #include "stdlib/math/base/assert/is_odd.h" #include "stdlib/math/base/assert/is_even.h" +#include "stdlib/constants/float64/max_safe_integer.h" +#include "stdlib/constants/float64/pinf.h" +#include "stdlib/constants/float64/ninf.h" #include /** @@ -33,6 +36,13 @@ * // returns true */ bool stdlib_base_is_odd( const double x ) { + // Every finite value whose magnitude exceeds the maximum safe integer is even, but `x-1` and `x+1` would round to an even value... + if ( x > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER ) { + return ( x == STDLIB_CONSTANT_FLOAT64_PINF ); + } + if ( x < -STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER ) { + return ( x == STDLIB_CONSTANT_FLOAT64_NINF ); + } // Check sign to prevent overflow... if ( x > 0.0 ) { return stdlib_base_is_even( x - 1.0 ); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.js b/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.js index 85f27eba4164..79eca2459583 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.js @@ -64,6 +64,28 @@ tape( 'the function returns `true` if provided an odd number', function test( t t.end(); }); +tape( 'the function returns `false` if provided a value whose magnitude exceeds the maximum safe integer', function test( t ) { + var values; + var v; + var i; + + values = [ + 9007199254740992.0, + 9007199254740994.0, + 1.152921504606847e18, + 1.0e300, + 1.7976931348623157e308 + ]; + for ( i = 0; i < values.length; i++ ) { + v = values[ i ]; + t.strictEqual( isOdd( v ), false, 'returns expected value when provided '+v ); + t.strictEqual( isOdd( -v ), false, 'returns expected value when provided '+(-v) ); + } + t.strictEqual( isOdd( 9007199254740991.0 ), true, 'returns expected value' ); + t.strictEqual( isOdd( -9007199254740991.0 ), true, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns `false` if provided `+-0`', function test( t ) { t.strictEqual( isOdd( +0.0 ), false, 'returns expected value' ); t.strictEqual( isOdd( -0.0 ), false, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.native.js b/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.native.js index 9ba3bafc48ae..04baebbbbdc3 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-odd/test/test.native.js @@ -73,6 +73,28 @@ tape( 'the function returns `true` if provided an odd number', opts, function te t.end(); }); +tape( 'the function returns `false` if provided a value whose magnitude exceeds the maximum safe integer', opts, function test( t ) { + var values; + var v; + var i; + + values = [ + 9007199254740992.0, + 9007199254740994.0, + 1.152921504606847e18, + 1.0e300, + 1.7976931348623157e308 + ]; + for ( i = 0; i < values.length; i++ ) { + v = values[ i ]; + t.strictEqual( isOdd( v ), false, 'returns expected value when provided '+v ); + t.strictEqual( isOdd( -v ), false, 'returns expected value when provided '+(-v) ); + } + t.strictEqual( isOdd( 9007199254740991.0 ), true, 'returns expected value' ); + t.strictEqual( isOdd( -9007199254740991.0 ), true, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns `false` if provided `+-0`', opts, function test( t ) { t.strictEqual( isOdd( +0.0 ), false, 'returns expected value' ); t.strictEqual( isOdd( -0.0 ), false, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-oddf/lib/main.js b/lib/node_modules/@stdlib/math/base/assert/is-oddf/lib/main.js index 202d1e369db0..664547d2d0b0 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-oddf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-oddf/lib/main.js @@ -22,6 +22,9 @@ var isEvenf = require( '@stdlib/math/base/assert/is-evenf' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var MAX_SAFE_INTEGER = require( '@stdlib/constants/float32/max-safe-integer' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); // MAIN // @@ -49,8 +52,16 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * // returns false */ function isOddf( x ) { - // Check sign to prevent overflow... x = float64ToFloat32( x ); + + // Every finite value whose magnitude exceeds the maximum safe integer is even, but `x-1` and `x+1` would round to an even value... + if ( x > MAX_SAFE_INTEGER ) { + return ( x === PINF ); + } + if ( x < -MAX_SAFE_INTEGER ) { + return ( x === NINF ); + } + // Check sign to prevent overflow... if ( x > 0.0 ) { return isEvenf( float64ToFloat32( x - 1.0 ) ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-oddf/manifest.json b/lib/node_modules/@stdlib/math/base/assert/is-oddf/manifest.json index cd3b9cf28638..e60ee9eaf499 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-oddf/manifest.json +++ b/lib/node_modules/@stdlib/math/base/assert/is-oddf/manifest.json @@ -40,7 +40,10 @@ "@stdlib/napi/argv-float", "@stdlib/napi/create-int32", "@stdlib/napi/export", - "@stdlib/math/base/assert/is-evenf" + "@stdlib/math/base/assert/is-evenf", + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" ] }, { @@ -54,7 +57,10 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-evenf" + "@stdlib/math/base/assert/is-evenf", + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" ] }, { @@ -68,7 +74,10 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-evenf" + "@stdlib/math/base/assert/is-evenf", + "@stdlib/constants/float32/max-safe-integer", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/assert/is-oddf/src/main.c b/lib/node_modules/@stdlib/math/base/assert/is-oddf/src/main.c index edb51a1061cb..2d12495a2f37 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-oddf/src/main.c +++ b/lib/node_modules/@stdlib/math/base/assert/is-oddf/src/main.c @@ -18,6 +18,9 @@ #include "stdlib/math/base/assert/is_oddf.h" #include "stdlib/math/base/assert/is_evenf.h" +#include "stdlib/constants/float32/max_safe_integer.h" +#include "stdlib/constants/float32/pinf.h" +#include "stdlib/constants/float32/ninf.h" #include /** @@ -33,6 +36,13 @@ * // returns true */ bool stdlib_base_is_oddf( const float x ) { + // Every finite value whose magnitude exceeds the maximum safe integer is even, but `x-1` and `x+1` would round to an even value... + if ( x > STDLIB_CONSTANT_FLOAT32_MAX_SAFE_INTEGER ) { + return ( x == STDLIB_CONSTANT_FLOAT32_PINF ); + } + if ( x < -STDLIB_CONSTANT_FLOAT32_MAX_SAFE_INTEGER ) { + return ( x == STDLIB_CONSTANT_FLOAT32_NINF ); + } // Check sign to prevent overflow... if ( x > 0.0f ) { return stdlib_base_is_evenf( x - 1.0f ); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-oddf/test/test.js b/lib/node_modules/@stdlib/math/base/assert/is-oddf/test/test.js index 32c78a0c3a40..c1e7b37d5784 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-oddf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-oddf/test/test.js @@ -64,6 +64,28 @@ tape( 'the function returns `true` if provided an odd number', function test( t t.end(); }); +tape( 'the function returns `false` if provided a value whose magnitude exceeds the maximum safe integer', function test( t ) { + var values; + var v; + var i; + + values = [ + 16777216.0, + 16777218.0, + 1073741824.0, + 1.0e30, + 3.4028234663852886e38 + ]; + for ( i = 0; i < values.length; i++ ) { + v = values[ i ]; + t.strictEqual( isOddf( v ), false, 'returns expected value when provided '+v ); + t.strictEqual( isOddf( -v ), false, 'returns expected value when provided '+(-v) ); + } + t.strictEqual( isOddf( 16777215.0 ), true, 'returns expected value' ); + t.strictEqual( isOddf( -16777215.0 ), true, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns `false` if provided `+-0`', function test( t ) { t.strictEqual( isOddf( +0.0 ), false, 'returns expected value' ); t.strictEqual( isOddf( -0.0 ), false, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-oddf/test/test.native.js b/lib/node_modules/@stdlib/math/base/assert/is-oddf/test/test.native.js index a1286aed0be6..cbcf4921eb3b 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-oddf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-oddf/test/test.native.js @@ -73,6 +73,28 @@ tape( 'the function returns `true` if provided an odd number', opts, function te t.end(); }); +tape( 'the function returns `false` if provided a value whose magnitude exceeds the maximum safe integer', opts, function test( t ) { + var values; + var v; + var i; + + values = [ + 16777216.0, + 16777218.0, + 1073741824.0, + 1.0e30, + 3.4028234663852886e38 + ]; + for ( i = 0; i < values.length; i++ ) { + v = values[ i ]; + t.strictEqual( isOddf( v ), false, 'returns expected value when provided '+v ); + t.strictEqual( isOddf( -v ), false, 'returns expected value when provided '+(-v) ); + } + t.strictEqual( isOddf( 16777215.0 ), true, 'returns expected value' ); + t.strictEqual( isOddf( -16777215.0 ), true, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns `false` if provided `+-0`', opts, function test( t ) { t.strictEqual( isOddf( +0.0 ), false, 'returns expected value' ); t.strictEqual( isOddf( -0.0 ), false, 'returns expected value' ); 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..a7510067f726 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 @@ -262,11 +262,10 @@ function pow( x, y ) { if ( x === 1.0 ) { return 1.0; } - if ( - x === -1.0 && - isOdd( y ) - ) { - return -1.0; + if ( x === -1.0 ) { + if ( isInteger( y ) ) { + return ( isOdd( y ) ) ? -1.0 : 1.0; + } } if ( isInfinite( x ) ) { if ( x === NINF ) { 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..7ab3b24c4209 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 @@ -618,11 +618,10 @@ double stdlib_base_pow( const double x, const double y ) { if ( xc == 1.0 ) { return 1.0; } - if ( - xc == -1.0 && - stdlib_base_is_odd( y ) - ) { - return -1.0; + if ( xc == -1.0 ) { + if ( stdlib_base_is_integer( y ) ) { + return ( stdlib_base_is_odd( y ) ) ? -1.0 : 1.0; + } } if ( stdlib_base_is_infinite( xc ) ) { if ( xc == STDLIB_CONSTANT_FLOAT64_NINF ) { 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..3917a0eec700 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,26 @@ tape( '`-1` raised to any odd integer is `-1`', function test( t ) { t.end(); }); +tape( '`-1` raised to any even integer is `1`', function test( t ) { + var values; + var i; + + values = [ + -1.0e300, + -3.6893488147419103e19, + -9007199254740994.0, + -2.0, + 2.0, + 9007199254740994.0, + 3.6893488147419103e19, + 1.0e300 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( pow( -1.0, values[ i ] ), 1.0, '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..af533640a701 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,26 @@ tape( '`-1` raised to any odd integer is `-1`', opts, function test( t ) { t.end(); }); +tape( '`-1` raised to any even integer is `1`', opts, function test( t ) { + var values; + var i; + + values = [ + -1.0e300, + -3.6893488147419103e19, + -9007199254740994.0, + -2.0, + 2.0, + 9007199254740994.0, + 3.6893488147419103e19, + 1.0e300 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( pow( -1.0, values[ i ] ), 1.0, 'returns expected value' ); + } + t.end(); +}); + tape( '`+-0` raised to `-infinity` is `+infinity`', opts, function test( t ) { var v;