summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/fpu.h
blob: ca42c60feb7119915f7f10c0dc2bc002c6725978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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