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?
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?
Share Improve this question asked Mar 8, 2012 at 9:37 HahiHahi 12110 bronze badges 1- 2 everything to the power of 0 is one - askamathematician./2010/12/… – scibuff Commented Mar 8, 2012 at 9:40
3 Answers
Reset to default 5That's what the specification says, so it's not a bug:
2. If
y
is +0, the result is 1, even ifx
is NaN.
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./#x15.8.2.13
No, it is not a bug. This behaviour is pliance with the ECMA definition of Javascript.