14

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

Jeffrey Sax
  • 10,253
  • 3
  • 29
  • 40
Chortos-2
  • 995
  • 7
  • 20
  • 1
    I'm not sure what you mean by "−∞0.5 is actually the imaginary number ∞i"; where have imaginary numbers come from? – Oliver Charlesworth Apr 28 '12 at 19:54
  • 2
    @OliCharlesworth standard math - taking the sqrt of a negative number gives an imaginary number. – Alnitak Apr 28 '12 at 19:56
  • 2
    @Alnitak: I'm not sure concepts such as "∞i" are particularly meaningful... – Oliver Charlesworth Apr 28 '12 at 19:58
  • @OliCharlesworth that's what most people say about imaginary numbers and about infinity, but there's no reason I know of that they can't be combined. – Alnitak Apr 28 '12 at 20:02
  • 1
    @Alnitak: Well, standard complex analysis has the [extended complex plane](http://en.wikipedia.org/wiki/Riemann_sphere), which has a single value of infinity... – Oliver Charlesworth Apr 28 '12 at 20:04
  • @OliCharlesworth ok, I'll conceded defeat on that one ;-) I'm very comfortable with complex numbers but the different types of infinity give me a headache. – Alnitak Apr 28 '12 at 20:12
  • In any case, ∞² = ∞ ≠ −∞, so −∞ to the 0.5 cannot be ∞. I’ve also just noticed and corrected a couple of silly mistakes in the maths in my question (added parentheses around −∞ and the second root, −∞i); sorry if they confused you. – Chortos-2 Apr 28 '12 at 20:22
  • @Chortos-2: I think the issue here is that you're trying to apply standard rules of arithmetic to infinity, which is not a real number. – Oliver Charlesworth Apr 28 '12 at 20:37
  • Imaginary number support is not available in standard the C library. – std''OrgnlDave Apr 28 '12 at 20:46
  • @OliCharlesworth At the very least `sqrt` and `pow` should give the same result. Note that the standard explicitly specifies return values for infinity inputs instead of just as explicitly leaving them undefined, and in most cases they ‘just make sense’. And while I think `pow(−∞, y)` for y > 0 and not an integer should give a NaN, I realize there may be good reason for it to give a positive infinity instead, and that reason is what I’m looking for. – Chortos-2 Apr 28 '12 at 20:53
  • @std''OrgnlDave It is in C99 (see complex.h), but of course you are right in that `pow` works with reals: that is exactly why I think it should return a NaN, because the proper imaginary result is not a real number. This is exactly what math.h functions do in other cases when the proper results are complex. – Chortos-2 Apr 28 '12 at 20:57

1 Answers1

16

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.

Jeffrey Sax
  • 10,253
  • 3
  • 29
  • 40
  • What if you consider (±1)/0 = ±∞, considering that "-0" is the identical real number "0"? – Heath Hunnicutt Apr 28 '12 at 21:28
  • @HeathHunnicutt `(-inf)^(1/2) = (-1/0)^(1/2) = (-1)^(1/2)/0 = nan/0 = nan` – Chortos-2 Apr 28 '12 at 21:36
  • 2
    This moves the question to "Why have -0 at all?" Well, one reason is that `-0` represents underflow from below. Another is that branch cuts in the complex plane, as they are traditionally defined, just work as expected with `-0`. – Jeffrey Sax Apr 28 '12 at 21:41
  • I still disagree with the standard about `pow(−∞, y)` (being able to derive positive infinity in addition to the two complex roots should only further support defining it as NaN), but this does explain where the standard behaviour comes from (or can come from). Thanks! – Chortos-2 Apr 28 '12 at 22:34
  • +1, the choice of IEEE to define pow this way doesn't make a lot of sense to me, but this is the first somewhat-reasonable argument I've seen for it. – R.. GitHub STOP HELPING ICE Apr 28 '12 at 22:50
  • @JeffreySax: I've long thought that IEEE-754 would have been much cleaner if it had positive and negative infinitesimals (which I'll call ptiny and ntiny), along with unsigned infinitesimal (utiny) and maybe "true" zero. That would allow consistent and symmetrical handling of axioms related to zero (including the equivalence of x+0, 0+x, and x). The only need to distinguish between unsigned infinitesimal and true zero would be when adding to a signed infinitesimal. Adding ptiny to utiny should yield utiny, but ptiny+0 should yield ptiny. – supercat Dec 30 '17 at 05:11