Why is pow(-infinity, positive non-integer) +infinity?

后端 未结 1 1652
清酒与你
清酒与你 2021-01-04 04:29

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

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

But, s

相关标签:
1条回答
  • 2021-01-04 04:54

    For odd integer y, it makes sense to define

    pow(±0, y) = ±0
    

    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.
    

    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.)

    Since 1/±0 = ±∞, and mathematically

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

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

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

    for y a positive non-integer.

    0 讨论(0)
提交回复
热议问题