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?
We can think of 1 / 0 = ∞ as the limit of 1 / z as z tends to zero
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.?
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.
来源:https://stackoverflow.com/questions/37841240/why-is-infinity-%c3%97-0-nan