Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 451
Dave Avatar asked Dec 15 '10 21:12

Dave


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)

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

like image 152
Arafangion Avatar answered Sep 19 '22 14:09

Arafangion