I've configured Visual Studio to throw floating point exceptions via the _controlfp function. This works for NAN and INF, but not QNAN. I.e. Quiet NaNs don't cause an exception to be raised. Is there any function, or config option for Visual Studio 2008/2010, that will force QNANs to instead be NANs, so that they throw exceptions?
-
I expect the answer to be 'no' but I'm very interested. – John Dibling Dec 15 '10 at 21:43
-
1another answer you may find useful: http://stackoverflow.com/questions/2769814/how-do-i-use-try-catch-to-catch-floating-point-errors/2769889#2769889 – George Dec 16 '10 at 02:09
-
Why? cant you just check the final calculation result, given the contagious nature of nans? – May 10 '12 at 18:53
-
@jdv-Jan de Vaan: Sure, but what good does that do you? If you're trying to track down an invalid input or bad calculation, you want it to fail as close to the source of the problem as possible. Checking the final result and saying "Yup, it's a NaN!" doesn't help you find the problem. – George May 12 '12 at 03:16
1 Answers
Some helpful tips, although I've never even remotely done something like this:
Read: http://www.cisl.ucar.edu/docs/trap.error/errortypes.html
The resulting search on the internet (which I've really only spent about 30 seconds on), leads me to believe that this is normally enabled with a compiler option.
However, I also seem to recall that such enabling/disabling of traps can be specified programmatically, and especially in windows, this can be done by pretty much any program, such as when a printer is used for printing. Additionally, if you change this option programmatically, please set it back to the previous value as soon as you can, otherwise if people from .NET try to use your code, they might have issues.
(In other words, your use of _controlfp could be overriden by some other routine, assuming that is indeed the correct approach to use)

- 1
- 1

- 11,517
- 1
- 40
- 72