
John Maddock wrote:
Hold on a second, C++ implements what the IEEE-754 standard requires FP arithmetic to do, and infinities and NaN are definitely part of that standard.
Hmmm - I want to clarifiy this. (The quoted text is from http://docs.sun.com/source/806-3568/ncg_goldberg.html) a) IEEE-754 does specify infinities and NaN C++ doesn't - C++ leaves it undefined and up to the implementation. b) IEEE-754 specifies flags to inquire as to the result of the last floating point operation. C++ doesn't specify anything about this. c) "The IEEE standard strongly recommends that implementations allow trap handlers to be installed." C++ doesn't permit this. On the other hand, the C++ standard library does support throwing exceptions from functions sine(x) for domain errors and such. So there's a mismatch here. d) "Another ambiguity in most language definitions concerns what happens on overflow, underflow and other exceptions. The IEEE standard precisely specifies the behavior of exceptions, and so languages that use the standard as a model can avoid any ambiguity on this point. " But C++ doesn't permit exceptions to be thrown in these instances.
I assure you that they do have legitimate uses,
Actually, the paper cited about give a good example of a such legitimate use. I believe such uses are far less common than people seem to think. Even the example cited in the paper wouldn't require saving and recovering from a text stream.
but more to the point, it's not only divide by zero that generates infinities, heck even addition (or subtraction) can generate infinities if push comes to shove.
Of course, I'm just using divide by zero as a one of the most common cases. But it occurs in other cases. So C++ is out of sync with IEEE-754. I see two ways to put it into sync. a) define what C++ should do for currently undefined operations like divide by zero and the others. b) require that C++ implementations throw exceptions when undefined operations are invoked. Until one of the above (or maybe something else) is done. There can really be no unambiguous resolution to the problem of passing results from undefined operations from one machine to another. Obviously, I believe that the adoption of b) above would result in fewer programs with hidden bugs. Robert Ramey