/src/core/stdc/fenv.d
D | 145 lines | 118 code | 14 blank | 13 comment | 6 complexity | b2a31bf4b6443dd200fcea49cfb942d7 MD5 | raw file
1/** 2 * D header file for C99. 3 * 4 * Copyright: Copyright Sean Kelly 2005 - 2009. 5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. 6 * Authors: Sean Kelly 7 * Standards: ISO/IEC 9899:1999 (E) 8 */ 9 10/* Copyright Sean Kelly 2005 - 2009. 11 * Distributed under the Boost Software License, Version 1.0. 12 * (See accompanying file LICENSE or copy at 13 * http://www.boost.org/LICENSE_1_0.txt) 14 */ 15module core.stdc.fenv; 16 17extern (C): 18@system: 19nothrow: 20 21version( Windows ) 22{ 23 struct fenv_t 24 { 25 ushort status; 26 ushort control; 27 ushort round; 28 ushort[2] reserved; 29 } 30 31 alias int fexcept_t; 32} 33else version( linux ) 34{ 35 struct fenv_t 36 { 37 ushort __control_word; 38 ushort __unused1; 39 ushort __status_word; 40 ushort __unused2; 41 ushort __tags; 42 ushort __unused3; 43 uint __eip; 44 ushort __cs_selector; 45 ushort __opcode; 46 uint __data_offset; 47 ushort __data_selector; 48 ushort __unused5; 49 } 50 51 alias int fexcept_t; 52} 53else version ( OSX ) 54{ 55 version ( BigEndian ) 56 { 57 alias uint fenv_t; 58 alias uint fexcept_t; 59 } 60 version ( LittleEndian ) 61 { 62 struct fenv_t 63 { 64 ushort __control; 65 ushort __status; 66 uint __mxcsr; 67 byte[8] __reserved; 68 } 69 70 alias ushort fexcept_t; 71 } 72} 73else version ( FreeBSD ) 74{ 75 struct fenv_t 76 { 77 ushort __control; 78 ushort __mxcsr_hi; 79 ushort __status; 80 ushort __mxcsr_lo; 81 uint __tag; 82 byte[16] __other; 83 } 84 85 alias ushort fexcept_t; 86} 87else 88{ 89 static assert( false, "Unsupported platform" ); 90} 91 92enum 93{ 94 FE_INVALID = 1, 95 FE_DENORMAL = 2, // non-standard 96 FE_DIVBYZERO = 4, 97 FE_OVERFLOW = 8, 98 FE_UNDERFLOW = 0x10, 99 FE_INEXACT = 0x20, 100 FE_ALL_EXCEPT = 0x3F, 101 FE_TONEAREST = 0, 102 FE_UPWARD = 0x800, 103 FE_DOWNWARD = 0x400, 104 FE_TOWARDZERO = 0xC00, 105} 106 107version( Windows ) 108{ 109 private extern fenv_t _FE_DFL_ENV; 110 fenv_t* FE_DFL_ENV = &_FE_DFL_ENV; 111} 112else version( linux ) 113{ 114 fenv_t* FE_DFL_ENV = cast(fenv_t*)(-1); 115} 116else version( OSX ) 117{ 118 private extern fenv_t _FE_DFL_ENV; 119 fenv_t* FE_DFL_ENV = &_FE_DFL_ENV; 120} 121else version( FreeBSD ) 122{ 123 private extern const fenv_t __fe_dfl_env; 124 const fenv_t* FE_DFL_ENV = &__fe_dfl_env; 125} 126else 127{ 128 static assert( false, "Unsupported platform" ); 129} 130 131void feraiseexcept(int excepts); 132void feclearexcept(int excepts); 133 134int fetestexcept(int excepts); 135int feholdexcept(fenv_t* envp); 136 137void fegetexceptflag(fexcept_t* flagp, int excepts); 138void fesetexceptflag(in fexcept_t* flagp, int excepts); 139 140int fegetround(); 141int fesetround(int round); 142 143void fegetenv(fenv_t* envp); 144void fesetenv(in fenv_t* envp); 145void feupdateenv(in fenv_t* envp);