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 )

      

or

Math.pow( Infinity, 0 )

      

it returns:

1

      

It's some kind of mistake?

+3


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.

+5


source


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): http://es5.github.com/#x15.8.2.13

+5


source


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

+1


source







All Articles