Math.pow and Infinity

There are seven indefinite forms in mathematics. Most of them return NaN in JavaScript. But when I try:

Math.pow( 0, 0 )



Math.pow( Infinity, 0 )


it returns:



It's some kind of mistake?


source to share

3 answers

What the spec says so it's not a bug:

2. If y

equal to +0, the result is 1, even if x

- NaN.



No, because anything is zero.

Not only is this easier to implement, it is mathematically correct (some mathematicians say pow(0, 0)

undefined, but the general convention is to accept pow(x, 0) == 1

for any x).

Also, it's in the spec (link officially stolen from primvdb):



No, this is not a mistake. This behavior conforms to the ECMA Javascript definition .



All Articles