5 ms·
The goal for floats isn't to resolve equations. It's to perform arithmetic. (1.0 / 0.0) has to be handled somehow. From a mathematical point of view, handlin
by palish 16y ago
The goal for floats isn't to resolve equations. It's to perform arithmetic. (1.0 / 0.0) has to be handled somehow.
From a mathematical point of view, handling it as "+infinity" has a 50/50 chance of being "correct". As floating-point math is inherently an approximation, this is a reasonable tradeoff.
But from a pragmatic point of view, you don't care about the result of "x * foo" if x is +infinity or -infinity. The result isn't usable.
- andos 15y ago1.0/0.0 has to be handled somehow. Yes, by raising an error [1]. Or whistling innocently and pretending it's not my code while leaving the room. handling it as "+infinity" has a 50/50 chance of being "correct" It has zero chance of being correct because infinity can never be the result of any arithmetic computation. Infinity is not a number. Infinity only appears as the result of evaluating limits, an operation which is not arithmetic. [1] http://en.wikipedia.org/wiki/SIGFPE http://en.wikipedia.org/wiki/SIGFPE
- marshray 15y agohttp://en.wikipedia.org/wiki/IEEE_754-1985 http://en.wikipedia.org/wiki/IEEE_754-1985 The spec allows the programmer to decide if the various degenerate cases in arithmetic will raise a signal, or result in a special value which propagates through the rest of the calcuations (INF, NaN, etc.). Certainly there are times to prefer one over the other, but the facilities that were standardized back in the 80's are generally more than adequate for most uses. Whether or not your platform C compiler lets you access these settings in a convenient and portable way is another question however...:-)