Reputation: 121
There are seven indeterminate forms in maths. Most of them returns NaN in JavaScript. But when i try:
Math.pow( 0, 0 )
or
Math.pow( Infinity, 0 )
it returns:
1
Is this some kind of bug?
Upvotes: 3
Views: 1750
Reputation: 117681
No, because anything to the power of zero is one.
Not only is this easier to implement, it is mathematically correct (some mathematicians say pow(0, 0)
is undefined, but general convention is to take pow(x, 0) == 1
for any x).
On top of that it is in the specification (link officialy stolen from primvdb): http://es5.github.com/#x15.8.2.13
Upvotes: 5
Reputation: 5213
No, it is not a bug. This behaviour is compliance with the ECMA definition of Javascript.
Upvotes: 1
Reputation: 154828
That's what the specification says, so it's not a bug:
2. If
y
is +0, the result is 1, even ifx
is NaN.
Upvotes: 5