diff options
Diffstat (limited to 'Build/source/utils/asymptote/fpu.h')
-rw-r--r-- | Build/source/utils/asymptote/fpu.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/fpu.h b/Build/source/utils/asymptote/fpu.h new file mode 100644 index 00000000000..5fa7205b43f --- /dev/null +++ b/Build/source/utils/asymptote/fpu.h @@ -0,0 +1,40 @@ +#ifndef FPU_H +#define FPU_H + +#ifdef HAVE_FENV_H +#ifdef _GNU_SOURCE +#define HAVE_FEENABLEEXCEPT +#endif +#endif + +#ifdef HAVE_FEENABLEEXCEPT +#include <fenv.h> + +inline Int fpu_exceptions() { + Int excepts=0; +#ifdef FE_INVALID + excepts |= FE_INVALID; +#endif +#ifdef FE_DIVBYZERO + excepts |= FE_DIVBYZERO; +#endif +#ifdef FE_OVERFLOW + excepts |= FE_OVERFLOW; +#endif + return excepts; +} + +inline void fpu_trap(bool trap=true) +{ + // Conditionally trap FPU exceptions on NaN, zero divide and overflow. + if(trap) feenableexcept(fpu_exceptions()); + else fedisableexcept(fpu_exceptions()); +} + +#else + +inline void fpu_trap(bool=true) {} + +#endif + +#endif |