Is there a rationale for Math.pow(-0, x)
evaluating to Infinity for all negative x
, except for the odd ones when it's -Infinity?
I mean:
Math.pow(-0, -6); // Infinity
Math.pow(-0, -7); // -Infinity
Math.pow(-0, -7.33); // Infinity
Math.pow(-0, -Infinity); // Infinity
Fiddle
I'm aware that a positive odd power of a negative number is negative, but this is clearly not the case here: -7 is not a positive exponent, and while -0 is indeed a number if you open your mind, it's not a negative one.
This behaviour makes mathematically no sense, and I don't see a practical use or technical convenience for it either, so I suspect the specification must rely on historical/compatibility reasons. Any insights?
pow Example. The method raises a to the power of b and returns the result as double. In other words, a is multiplied by itself b times.
The pow( ) method can be used to raise any number to any power. If exponent is negative, pow( ) returns 1 / ( base abs(exponent)).
The pow() function is used to find the nth power of a value. There are two types of pow() function: inbuilt and imported from the math module. The inbuilt pow() function accepts three arguments (base, exponent, and modulus), out of which the third argument (modulus) is optional.
It's a static method on Math class, which means you don't have to instantiate a Math instance to call it. The power of a number is the number of times the number is multiplied by itself.
I believe this is for consistency with powers of other negative numbers. When you raise a negative number to an even power, you always get a positive result. But when you raise a negative number to an odd power, you get a negative result. Raising zero to a negative power always results in infinity (because it's equivalent to dividing by zero); in the case of negative zero, the sign alternates just like other negative numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With