1 /** 2 * D header file for C99. 3 * 4 * Copyright: Public Domain 5 * License: Public Domain 6 * Authors: Sean Kelly, Walter Bright 7 * Standards: ISO/IEC 9899:1999 (E) 8 */ 9 module tango.stdc.fenv; 10 11 extern (C): 12 13 version( Win32 ) 14 { 15 struct fenv_t 16 { 17 ushort status; 18 ushort control; 19 ushort round; 20 ushort[2] reserved; 21 } 22 23 alias int fexcept_t; 24 } 25 else version( linux ) 26 { 27 struct fenv_t 28 { 29 ushort __control_word; 30 ushort __unused1; 31 ushort __status_word; 32 ushort __unused2; 33 ushort __tags; 34 ushort __unused3; 35 uint __eip; 36 ushort __cs_selector; 37 ushort __opcode; 38 uint __data_offset; 39 ushort __data_selector; 40 ushort __unused5; 41 } 42 43 alias int fexcept_t; 44 } 45 else version(OSX) 46 { 47 version ( BigEndian ) 48 { 49 alias uint fenv_t; 50 alias uint fexcept_t; 51 } 52 version ( LittleEndian ) 53 { 54 struct fenv_t 55 { 56 ushort __control; 57 ushort __status; 58 uint __mxcsr; 59 byte[8] __reserved; 60 } 61 62 alias ushort fexcept_t; 63 } 64 } 65 else version (FreeBSD) 66 { 67 struct fenv_t 68 { 69 ushort __control; 70 ushort __mxcsr_hi; 71 ushort __status; 72 ushort __mxcsr_lo; 73 uint __tag; 74 byte[16] __other; 75 } 76 77 alias ushort fexcept_t; 78 } 79 else version ( solaris ) 80 { 81 private import tango.stdc.config; 82 83 struct __fex_handler_struct 84 { 85 int __mode; 86 void function() handler; 87 } 88 alias __fex_handler_struct[12] __fex_handler_t; 89 90 struct fenv_t 91 { 92 __fex_handler_t __handlers; 93 c_ulong __fsr; 94 } 95 96 alias int fexcept_t; 97 } 98 else 99 { 100 static assert( false ); 101 } 102 103 enum 104 { 105 FE_INVALID = 1, 106 FE_DENORMAL = 2, // non-standard 107 FE_DIVBYZERO = 4, 108 FE_OVERFLOW = 8, 109 FE_UNDERFLOW = 0x10, 110 FE_INEXACT = 0x20, 111 FE_ALL_EXCEPT = 0x3F, 112 FE_TONEAREST = 0, 113 FE_UPWARD = 0x800, 114 FE_DOWNWARD = 0x400, 115 FE_TOWARDZERO = 0xC00, 116 } 117 118 version( Win32 ) 119 { 120 private extern const fenv_t _FE_DFL_ENV; 121 const fenv_t* FE_DFL_ENV = &_FE_DFL_ENV; 122 } 123 else version( linux ) 124 { 125 fenv_t* FE_DFL_ENV = cast(fenv_t*)(-1); 126 } 127 else version(OSX) 128 { 129 private extern const fenv_t _FE_DFL_ENV; 130 const fenv_t* FE_DFL_ENV = &_FE_DFL_ENV; 131 } 132 else version( FreeBSD ) 133 { 134 private extern const fenv_t __fe_dfl_env; 135 const fenv_t* FE_DFL_ENV = &__fe_dfl_env; 136 } 137 else version( solaris ) 138 { 139 private extern const fenv_t __fenv_dfl_env; 140 const fenv_t* FE_DFL_ENV = &__fe_dfl_env; 141 } 142 else 143 { 144 static assert( false ); 145 } 146 147 void feraiseexcept(int excepts); 148 void feclearexcept(int excepts); 149 150 int fetestexcept(int excepts); 151 int feholdexcept(fenv_t* envp); 152 153 void fegetexceptflag(fexcept_t* flagp, int excepts); 154 void fesetexceptflag(in fexcept_t* flagp, int excepts); 155 156 int fegetround(); 157 int fesetround(int round); 158 159 void fegetenv(fenv_t* envp); 160 void fesetenv(in fenv_t* envp); 161 void feupdateenv(in fenv_t* envp);