In IEEE 754-2008 section "9.2.1 Special values" there is mentioned that
pow(+1, y)
is1
for anyy
(even a quietNaN
)
For not reading the entire document Wikipedia gives the shortcut:
The 2008 version of the IEEE 754 standard says that
pow(1, qNaN)
andpow(qNaN, 0)
should both return1
since they return1
whatever else is used instead of quietNaN
.
Why then Math.pow(1, NaN)
is NaN
in JavaScript? Doesn't it follow the standards?
It's because the ECMAscript specification seems to say so.
pow (x, y)
Returns an implementation-dependent approximation to the result of raising
x
to the powery
.
- If
y
isNaN
, the result isNaN
.- ... other constraints...
According to the Wikipedia article that pow
definition was added to IEEE 754 in 2008. It's also optional.
On the other hand, ECMAScript's pow
has been defined to return NaN
if the second argument is NaN
since at least 1997, in section 15.8.2.13 of that year's standard.
It would seem the ECMA committee chose to maintain compatibility with over a decade of JavaScript over complying with IEEE's peculiar new suggestion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With