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.
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.)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 get0
as it can't be any smaller. When you multiply Infinity with0
you get "Not A Number", as someone decided that would be the logical thing to do, and put it in the spec.