Skip to content

Instantly share code, notes, and snippets.

@matthieuheitz
Created March 29, 2017 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthieuheitz/8a84a2322528bd5237452d5f511790b6 to your computer and use it in GitHub Desktop.
Save matthieuheitz/8a84a2322528bd5237452d5f511790b6 to your computer and use it in GitHub Desktop.
Catching Floating point exceptions
// 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