Skip to main content
 首页 » 编程设计

python之为什么 1**Inf 的值等于 1,而不是 NaN

2025年05月04日14mfrbuaa

为什么 1**Inf == 1 ?

我相信它应该是 NaN,就像 Inf-Inf 或 Inf/Inf 一样。

如何在 python 中对 float 求幂? exp(y*log(x)) 会得到正确的结果:/

请您参考如下方法:

你是对的,数学上,the value of 1∞ is indeterminate .

但是,在这种情况下,Python 并没有完全遵循数学原理。 The document of math.pow说:

math.pow(x, y) 

Return x raised to the power y. Exceptional cases follow Annex ‘F’ of the C99 standard as far as possible. In particular, pow(1.0, x) and pow(x, 0.0) always return 1.0, even when x is a zero or a NaN.