| 1 | /** |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. |
| 3 | * This file is part of the mingw-w64 runtime package. |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. |
| 5 | */ |
| 6 | #ifndef _FENV_H_ |
| 7 | #define _FENV_H_ |
| 8 | |
| 9 | #include <float.h> |
| 10 | |
| 11 | |
| 12 | /* FPU status word exception flags */ |
| 13 | #define FE_INEXACT _SW_INEXACT |
| 14 | #define FE_UNDERFLOW _SW_UNDERFLOW |
| 15 | #define FE_OVERFLOW _SW_OVERFLOW |
| 16 | #define FE_DIVBYZERO _SW_ZERODIVIDE |
| 17 | #define FE_INVALID _SW_INVALID |
| 18 | #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) |
| 19 | |
| 20 | /* FPU control word rounding flags */ |
| 21 | #define FE_TONEAREST _RC_NEAR |
| 22 | #define FE_UPWARD _RC_UP |
| 23 | #define FE_DOWNWARD _RC_DOWN |
| 24 | #define FE_TOWARDZERO _RC_CHOP |
| 25 | |
| 26 | #if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) |
| 27 | |
| 28 | /* Amount to shift by to convert an exception to a mask bit. */ |
| 29 | #define FE_EXCEPT_SHIFT 0x08 |
| 30 | |
| 31 | #else |
| 32 | |
| 33 | /* The MXCSR exception flags are the same as the |
| 34 | FE flags. */ |
| 35 | #define __MXCSR_EXCEPT_FLAG_SHIFT 0 |
| 36 | |
| 37 | /* How much to shift FE status word exception flags |
| 38 | to get the MXCSR exeptions masks, */ |
| 39 | #define __MXCSR_EXCEPT_MASK_SHIFT 7 |
| 40 | |
| 41 | /* How much to shift FE status word exception flags |
| 42 | to get MXCSR rounding flags, */ |
| 43 | #define __MXCSR_ROUND_FLAG_SHIFT 3 |
| 44 | |
| 45 | #endif /* defined(_ARM_) || defined(__arm__) */ |
| 46 | |
| 47 | #ifndef RC_INVOKED |
| 48 | |
| 49 | typedef struct |
| 50 | { |
| 51 | unsigned long _Fe_ctl; |
| 52 | unsigned long _Fe_stat; |
| 53 | } fenv_t; |
| 54 | |
| 55 | /* Type representing exception flags. */ |
| 56 | typedef unsigned long fexcept_t; |
| 57 | |
| 58 | #ifdef __cplusplus |
| 59 | extern "C" { |
| 60 | #endif |
| 61 | |
| 62 | /* The FE_DFL_ENV macro is required by standard. |
| 63 | fesetenv will use the environment set at app startup.*/ |
| 64 | extern const fenv_t __mingw_fe_dfl_env; |
| 65 | #define FE_DFL_ENV (&__mingw_fe_dfl_env) |
| 66 | |
| 67 | /* The C99 standard (7.6.9) allows us to define implementation-specific macros for |
| 68 | different fp environments */ |
| 69 | #if defined(__i386__) || defined(__x86_64__) |
| 70 | |
| 71 | /* The default Intel x87 floating point environment (64-bit mantissa) */ |
| 72 | extern const fenv_t __mingw_fe_pc64_env; |
| 73 | #define FE_PC64_ENV (&__mingw_fe_pc64_env) |
| 74 | |
| 75 | /* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */ |
| 76 | extern const fenv_t __mingw_fe_pc53_env; |
| 77 | #define FE_PC53_ENV (&__mingw_fe_pc53_env) |
| 78 | |
| 79 | #endif |
| 80 | |
| 81 | /*TODO: Some of these could be inlined */ |
| 82 | /* 7.6.2 Exception */ |
| 83 | |
| 84 | extern int __cdecl feclearexcept (int _Flags); |
| 85 | extern int __cdecl fegetexceptflag (fexcept_t * _Flagp, int _Excepts); |
| 86 | extern int __cdecl feraiseexcept (int _Excepts); |
| 87 | extern int __cdecl fesetexceptflag (const fexcept_t * _Flagp, int _Excepts); |
| 88 | extern int __cdecl fetestexcept (int _Excepts); |
| 89 | |
| 90 | /* 7.6.3 Rounding */ |
| 91 | |
| 92 | extern int __cdecl fegetround (void); |
| 93 | extern int __cdecl fesetround (int _Mode); |
| 94 | |
| 95 | /* 7.6.4 Environment */ |
| 96 | |
| 97 | extern int __cdecl fegetenv(fenv_t * _Envp); |
| 98 | extern int __cdecl fesetenv(const fenv_t * _Envp); |
| 99 | extern int __cdecl feupdateenv(const fenv_t * _Envp); |
| 100 | extern int __cdecl feholdexcept(fenv_t * _Envp); |
| 101 | |
| 102 | #ifdef _GNU_SOURCE |
| 103 | extern int __cdecl feenableexcept(int _Excepts); |
| 104 | extern int __cdecl fedisableexcept(int _Excepts); |
| 105 | extern int __cdecl fegetexcept(void); |
| 106 | #endif |
| 107 | |
| 108 | #ifdef __cplusplus |
| 109 | } |
| 110 | #endif |
| 111 | #endif	/* Not RC_INVOKED */ |
| 112 | |
| 113 | #endif /* ndef _FENV_H */ |