]>
Commit | Line | Data |
---|---|---|
9ef1c2d9 | 1 | // |
2 | // from: http://www.fortran-2000.com/ArnaudRecipes/CompilerTricks.html | |
3 | // | |
4 | ||
5 | // Starting with glibc 2.2, the following C99-style (but glibc specific) | |
6 | // code is preferred. | |
7 | ||
8 | // #define _GNU_SOURCE 1 | |
9 | // #include <fenv.h> | |
10 | // static void __attribute__ ((constructor)) trapfpe(void) | |
11 | // { | |
12 | // /* Enable some exceptions. At startup all exceptions are masked. */ | |
13 | // feenableexcept(FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW); | |
14 | // } | |
15 | ||
16 | ||
17 | ||
18 | // Previous versions of glibc require the following code. | |
19 | // trapfpe.c | |
20 | ||
21 | #include <fpu_control.h> | |
22 | static void __attribute__ ((constructor)) trapfpe(void) | |
23 | { | |
24 | fpu_control_t cw = | |
25 | _FPU_DEFAULT & ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM); | |
26 | _FPU_SETCW(cw); | |
27 | /* On x86, this expands to: */ | |
28 | /* unsigned int cw = 0x037f & ~(0x01 | 0x04 | 0x08); */ | |
29 | /* __asm__ ("fldcw %0" : : "m" (*&cw)); */ | |
30 | } |