C99 annex F (IEEE floating point support) says this:
pow(−∞, y)
returns +∞ for y > 0 and not an odd integer.
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 +∞?
(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.)
For odd integer
y
, it makes sense to defineAfter 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 defineThe sign is undefined. But we don't set this to
NaN
for-0
for the same reason we don't setsqrt(-0)
equal toNaN
: 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
then setting
x=±∞
in the above, leads to:for
y
a positive non-integer.