为什么pow(-infinity,正非整数)+ infinity? [英] Why is pow(-infinity, positive non-integer) +infinity?

查看:100
本文介绍了为什么pow(-infinity,正非整数)+ infinity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C99附件F(IEEE浮点支持)表示:

C99 annex F (IEEE floating point support) says this:

pow(−∞, y)对于y> 0而不是奇整数返回+∞.

pow(−∞, y) returns +∞ for y > 0 and not an odd integer.

但是,例如,(−∞) 0.5 实际上具有假想值±∞i,而不是+∞. C99自己的sqrt(−∞)返回NaN并按预期生成域错误.为什么然后pow要求返回+∞?

But, say, (−∞)0.5 actually has the imaginary values ±∞i, not +∞. C99’s own sqrt(−∞) returns a NaN and generates a domain error as expected. Why then is pow required to return +∞?

(大多数其他语言都直接使用C库,或者像这种情况下的Python一样,按照标准复制它的行为,因此在实践中,这不仅影响到C99,而且还影响更多.)

(Most other languages use the C library directly or, like Python in this case, copy the behaviour required of it by standards, so in practice this affects more than just C99.)

推荐答案

对于奇数整数y,定义是有意义的

For odd integer y, it makes sense to define

pow(±0, y) = ±0

毕竟,提高到奇数幂总是会保留符号.如果我们可以保留零的符号,我们也可以这样做.对于正 non -整数y,我们应定义

After all, raising to an odd power always preserves the sign. If we can preserve the sign of zero, we might as well do it. For positive non-integer y, we should define

pow(±0, y) = +0.

符号未定义.但是出于与未将sqrt(-0)设置为NaN相同的原因,我们没有为-0将其设置为NaN:只是没有意义. (FWIW,这也是在IEEE-754-2008标准的9.2.1节中定义的方式.)

The sign is undefined. But we don't set this to NaN for -0 for the same reason we don't set sqrt(-0) equal to NaN: it just wouldn't make sense. (FWIW, this is also how it is defined in section 9.2.1 of the IEEE-754-2008 standard.)

由于1/±0 =±∞,因此在数学上

Since 1/±0 = ±∞, and mathematically

pow(x,y) = 1/pow(1/x,y)

然后在上面设置x=±∞会导致:

then setting x=±∞ in the above, leads to:

pow(±∞,y) = 1/pow(±0,y) = 1/+0 = +∞

y为正非整数.

这篇关于为什么pow(-infinity,正非整数)+ infinity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆