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?
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
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.
No, it is not a bug. This behaviour is compliance with the ECMA definition of Javascript .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.