Re: Portability and floating point exceptions
George Neuner wrote:
On Thu, 28 Jan 2010 12:06:33 CST, Pete Becker
<pete@versatilecoding.com> wrote:
Andrew wrote:
some NaN or results may be issued by the floating-point unit and be
returned as such to the application without any warning better than
the value of the result.
Yes, that's how IEEE floats are designed: don't check for errors until
the end. That way your code runs flat out in normal execution, and code
that runs into errors perhaps runs further than it otherwise would. But
if you read carefully about how NaN values and infinities propagate,
you'll see that you don't lose them, so checking at the end is safe.
The problem with quiet NaNs (and also with INFs) is that isn't easy to
identify the particular operation or data that caused your complex
computation to fail unless you check the results at every step. It
only gets worse using SIMD. It doesn't help that most FP hardware
doesn't support signaling NaNs with an interrupt and so, in most
cases, implementing language level exceptions requires slowing
calculations by inserting extra check code.
The goal isn't making it easy to debug your code and validate input,
it's to make math operations run as fast as possible on valid values.
For debugging, enable floating-point exceptions and add your own
exception handlers. (Note: this has nothing to do with C++ exceptions;
floating-point math has its own idea of what constitutes an exception).
I don't know how intrusive that is in the real world; I'm not an expert
on floating-point math.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]