Force all QNaN to instead be normal NaN (SNaN) so exceptions are thrown
Asked Answered
C

1

9

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?

Charmain answered 15/12, 2010 at 21:34 Comment(4)
I expect the answer to be 'no' but I'm very interested.Flounce
another answer you may find useful: #2770314Raglan
Why? cant you just check the final calculation result, given the contagious nature of nans?Snowber
@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.Raglan
C
1

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)

Also see Visual Studio C++ 2008 / 2010 - break on float NaN

Calvert answered 16/12, 2010 at 2:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.