4

IEEE 754 specifies the result of 1 / 0 as ∞ (Infinity).

However, IEEE 754 then specifies the result of 0 × ∞ as NaN.

This feels counter-intuitive: Why is 0 × ∞ not 0?

  1. We can think of 1 / 0 = ∞ as the limit of 1 / z as z tends to zero

  2. We can think of 0 × ∞ = 0 as the limit of 0 × z as z tends to ∞.

Why does the IEEE standard follow intuition 1. but not 2.?

13
  • 1
    Because Infinity isn't a concrete number? Jun 15, 2016 at 16:49
  • 2
  • 1
    But in the case of Infinity / 0, doesn't the division by zero take precedence over whatever happens to be in the numerator? (I'm not arguing mathematics rigorously here. I'm just guessing the intent of the language author.) Jun 15, 2016 at 16:52
  • 1
    Infinity is a number in javascript, at least by type, but it's not really a concrete number, it's not, say, 7 or anything like that, it's more of a concept, "the largest number there is" etc. When you multiply infinity with any positive or negative number, you get positive or negative Infinity, as it can't be any larger. When you divide a number by Infinity, you get 0 as it can't be any smaller. When you multiply Infinity with 0 you get "Not A Number", as someone decided that would be the logical thing to do, and put it in the spec.
    – adeneo
    Jun 15, 2016 at 16:54
  • 3
    Why not think of 0*Infinity as the limit of x*infinity as x tends to zero? It makes as much sense as the other way round. The problem with 0*Infinity, and the reason it should be a NaN, is that it is possible to come up with a case for 0, Infinity, and anything in between. Jun 15, 2016 at 20:02

1 Answer 1

9

It is easier to understand the behavior of IEEE 754 floating point zeros and infinities if you do not think of them as being literally zero or infinite.

The floating point zeros not only represent the real number zero. They also represent all real numbers that would round to something smaller than the smallest subnormal. That is why zero is signed. Even tiny numbers do have a sign if they are not actually zero.

Similarly, each infinity also represents all numbers with the corresponding sign that would round to something with a magnitude that would not fit in the finite range.

NaN represents either "No real number result", for example sqrt(-1), or "Haven't a clue".

Something very big divided by something very small is very, very big, so `Infinity / 0 == Infinity".

Something very big multiplied by something very small could be anything, depending on the actual magnitudes that we don't know. Since the result could be anything from very small through very big, NaN is the most reasonable answer.

=================================================================

Although I think the above is the best way to understand practical floating point behavior, a similar issue arises in real number limits.

Suppose f(x) tends to infinity and g(x) tends to zero as x tends to infinity. It is easy to prove that f(x)/g(x) tends to infinity as x tends to infinity. On the other hand, it is not possible to prove anything about the limit of f(x)*g(x) without more information about the functions.

10
  • So we should think of 0 more as a very small quantity instead of actual 0, since it is the result of many arithmetic computations for which arithmetic underflow occurs? That seems sensible!
    – le_m
    Jun 15, 2016 at 18:17
  • I disagree with this answer. Thinking of floating-point numbers as representing small ranges of values is the root of much confusion, and we should not encourage it. Zeroes represent exactly zero (a fact the OP has no trouble with, otherwise they would not accept that 0 times anything should be zero so easily) and infinities represent exceptional values conceptually beyond all reals (this is the point that the OP does not already accept). Jun 15, 2016 at 21:08
  • 2
    @PascalCuoq In your model, what is negative zero and why does it exist? Jun 15, 2016 at 21:12
  • 3
    @PascalCuoq Never comparing floating-point values with "==" is non-sense and this "rule" is repeated mindlessly without justification, not by recourse to a "small interval" model, as far as I have seen. To my knowledge, -0 exists not simply for the convenience of format orthogonality, but by conscious design: see Kahan's paper on branch cuts in complex functions, -0 represents a limit when approaching zero from below; also for smooth interaction with infinities, e.g. 1/x where x is negative and underflows. Not producing digits unnecessary to uniquely identify a binary64 seems fine to me?
    – njuffa
    Jun 16, 2016 at 14:23
  • 4
    My view of floating-point numbers is similar to wave/particle dualism in physics: Sometimes it is best to think of an fp number as a point, at other times it is best to think of it as an interval, depending on context. When dealing with large arguments to trig functions, a library writer has no knowledge of which context-dependend view is appropriate, so needs to err on the conservative (point) side. As for sqrt(-0)==0, I don't recall what drove that, it does not make sense under an "approach zero in the negative half-plane (via underflow)" mental model, but needed for consistency with +0==-0?
    – njuffa
    Jun 16, 2016 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.