在IEEE 754-2008节"9.2.1 Special values"有提到
pow(+1, y)
is1
for anyy
(even a quietNaN
)
如果没有阅读整个文档,维基百科给出了 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
.
为什么 Math.pow(1, NaN)
在 JavaScript 中是 NaN
?不符合标准吗?
最佳答案
是因为the ECMAscript specification好像是这么说的。
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...
关于javascript - 为什么 Math.pow(1, NaN) 在 JavaScript 中等于 NaN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14937880/