Created
March 29, 2017 18:15
-
-
Save matthieuheitz/8a84a2322528bd5237452d5f511790b6 to your computer and use it in GitHub Desktop.
Catching Floating point exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For Linux machines | |
#include <fenv.h> // or <cfenv> but only for C++11 | |
// Enable all exceptions except for INEXACT | |
feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); | |
// More info at https://linux.die.net/man/3/feenableexcept | |
// For machines using SSE (Apple, etc.) | |
#include <xmmintrin.h> | |
// Disable only INVALID exception | |
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID); | |
// Enable the overflow and underflow exceptions and disable all others | |
_MM_SET_EXCEPTION_MASK(MM_MASK_OVERFLOW | _MM_MASK_UNDERFLOW) | |
// More info at http://technion.ac.il/doc/intel/compiler_c/main_cls/intref_cls/common/intref_sse_macro_readwrite_reg.htm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment