为什么无穷大的 0 次幂被实现为 1?
Why infinity to power 0 is implemented to be 1?
这是数学中的不确定形式,但在 Python 和 JavaScript 中它的结果是 1。
在
中测试
Python:
inf=float('inf')
print(inf**0)
JavaScript
console.log(Math.pow(Infinity,0))
console.log(Infinity**0)
规范就是这样定义的:
6.1.6.1.3 Number::exponentiate ( base, exponent )
Returns an implementation-dependent approximation of the result of raising base to the power exponent.
If exponent is NaN, the result is NaN.
If exponent is +0, the result is 1, even if base is NaN.
[...]
来源:https://tc39.es/ecma262/#sec-numeric-types-number-exponentiate(回答者强调)
这是数学中的不确定形式,但在 Python 和 JavaScript 中它的结果是 1。 在
中测试Python:
inf=float('inf')
print(inf**0)
JavaScript
console.log(Math.pow(Infinity,0))
console.log(Infinity**0)
规范就是这样定义的:
6.1.6.1.3 Number::exponentiate ( base, exponent )
Returns an implementation-dependent approximation of the result of raising base to the power exponent.
If exponent is NaN, the result is NaN.
If exponent is +0, the result is 1, even if base is NaN.
[...]
来源:https://tc39.es/ecma262/#sec-numeric-types-number-exponentiate(回答者强调)