float.h (10989B) - Raw
1 /* 2 * float.h 3 * This file has no copyright assigned and is placed in the Public Domain. 4 * This file is part of the mingw-runtime package. 5 * No warranty is given; refer to the file DISCLAIMER.PD within the package. 6 * 7 * Constants related to floating point arithmetic. 8 * 9 * Also included here are some non-ANSI bits for accessing the floating 10 * point controller. 11 * 12 */ 13 14 #if defined(__LIBMSVCRT__) 15 /* When building mingw-w64, this should be blank. */ 16 #define _SECIMP 17 #else 18 #ifndef _SECIMP 19 #define _SECIMP __declspec(dllimport) 20 #endif /* _SECIMP */ 21 #endif /* defined(__LIBMSVCRT__) */ 22 23 #if (defined (__GNUC__) && defined (__GNUC_MINOR__)) \ 24 || (defined(__clang__) && defined(__clang_major__)) 25 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)) \ 26 || (__clang_major__ >=3) 27 #if !defined(_FLOAT_H___) && !defined(__FLOAT_H) && !defined(__CLANG_FLOAT_H) 28 #include_next <float.h> 29 #endif 30 #elif !defined (_FLOAT_H___) 31 #if (__GNUC__ < 4) 32 #error Corrupt install of gcc-s internal headers, or search order was changed. 33 #else 34 /* #include_next <float_ginclude.h> */ 35 36 /* Number of decimal digits, q, such that any floating-point number with q 37 decimal digits can be rounded into a floating-point number with p radix b 38 digits and back again without change to the q decimal digits, 39 40 p * log10(b) if b is a power of 10 41 floor((p - 1) * log10(b)) otherwise 42 */ 43 #undef FLT_DIG 44 #undef DBL_DIG 45 #undef LDBL_DIG 46 #define FLT_DIG __FLT_DIG__ 47 #define DBL_DIG __DBL_DIG__ 48 #define LDBL_DIG __LDBL_DIG__ 49 50 51 /* Maximum representable finite floating-point number, 52 53 (1 - b**-p) * b**emax 54 */ 55 #undef FLT_MAX 56 #undef DBL_MAX 57 #undef LDBL_MAX 58 #define FLT_MAX __FLT_MAX__ 59 #define DBL_MAX __DBL_MAX__ 60 #define LDBL_MAX __LDBL_MAX__ 61 62 63 /* Minimum normalized positive floating-point number, b**(emin - 1). */ 64 #undef FLT_MIN 65 #undef DBL_MIN 66 #undef LDBL_MIN 67 #define FLT_MIN __FLT_MIN__ 68 #define DBL_MIN __DBL_MIN__ 69 #define LDBL_MIN __LDBL_MIN__ 70 71 /* Needed for libjava building - Victor K. */ 72 73 /* Radix of exponent representation, b. */ 74 #undef FLT_RADIX 75 #define FLT_RADIX __FLT_RADIX__ 76 77 /* Minimum int x such that FLT_RADIX**(x-1) is a normalized float, emin */ 78 #undef FLT_MIN_EXP 79 #undef DBL_MIN_EXP 80 #undef LDBL_MIN_EXP 81 #define FLT_MIN_EXP __FLT_MIN_EXP__ 82 #define DBL_MIN_EXP __DBL_MIN_EXP__ 83 #define LDBL_MIN_EXP __LDBL_MIN_EXP__ 84 85 /* Minimum negative integer such that 10 raised to that power is in the 86 range of normalized floating-point numbers, 87 88 ceil(log10(b) * (emin - 1)) 89 */ 90 #undef FLT_MIN_10_EXP 91 #undef DBL_MIN_10_EXP 92 #undef LDBL_MIN_10_EXP 93 #define FLT_MIN_10_EXP __FLT_MIN_10_EXP__ 94 #define DBL_MIN_10_EXP __DBL_MIN_10_EXP__ 95 #define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ 96 97 /* Maximum int x such that FLT_RADIX**(x-1) is a representable float, emax. */ 98 #undef FLT_MAX_EXP 99 #undef DBL_MAX_EXP 100 #undef LDBL_MAX_EXP 101 #define FLT_MAX_EXP __FLT_MAX_EXP__ 102 #define DBL_MAX_EXP __DBL_MAX_EXP__ 103 #define LDBL_MAX_EXP __LDBL_MAX_EXP__ 104 105 /* Maximum integer such that 10 raised to that power is in the range of 106 representable finite floating-point numbers, 107 108 floor(log10((1 - b**-p) * b**emax)) 109 */ 110 #undef FLT_MAX_10_EXP 111 #undef DBL_MAX_10_EXP 112 #undef LDBL_MAX_10_EXP 113 #define FLT_MAX_10_EXP __FLT_MAX_10_EXP__ 114 #define DBL_MAX_10_EXP __DBL_MAX_10_EXP__ 115 #define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ 116 117 /* Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown. */ 118 /* ??? This is supposed to change with calls to fesetround in <fenv.h>. */ 119 #undef FLT_ROUNDS 120 #define FLT_ROUNDS 1 121 122 #undef FLT_EPSILON 123 #undef DBL_EPSILON 124 #undef LDBL_EPSILON 125 #define FLT_EPSILON __FLT_EPSILON__ 126 #define DBL_EPSILON __DBL_EPSILON__ 127 #define LDBL_EPSILON __LDBL_EPSILON__ 128 129 #define _FLOAT_H___ 130 #endif 131 #endif 132 #endif 133 134 #ifndef _MINGW_FLOAT_H_ 135 #define _MINGW_FLOAT_H_ 136 137 /* All the headers include this file. */ 138 #include <crtdefs.h> 139 140 /* 141 * Functions and definitions for controlling the FPU. 142 */ 143 144 /* TODO: These constants are only valid for x86 machines */ 145 146 /* Control word masks for unMask */ 147 #define _MCW_DN 0x03000000 /* Denormal control */ 148 #define _MCW_EM 0x0008001F /* Error masks */ 149 #define _MCW_IC 0x00040000 /* Infinity */ 150 #define _MCW_RC 0x00000300 /* Rounding */ 151 #define _MCW_PC 0x00030000 /* Precision */ 152 153 /* Number of base-FLT_RADIX digits in the significand, p. */ 154 #undef FLT_MANT_DIG 155 #undef DBL_MANT_DIG 156 #undef LDBL_MANT_DIG 157 #define FLT_MANT_DIG __FLT_MANT_DIG__ 158 #define DBL_MANT_DIG __DBL_MANT_DIG__ 159 #define LDBL_MANT_DIG __LDBL_MANT_DIG__ 160 161 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 162 /* The floating-point expression evaluation method. 163 -1 indeterminate 164 0 evaluate all operations and constants just to the range and 165 precision of the type 166 1 evaluate operations and constants of type float and double 167 to the range and precision of the double type, evaluate 168 long double operations and constants to the range and 169 precision of the long double type 170 2 evaluate all operations and constants to the range and 171 precision of the long double type 172 173 ??? This ought to change with the setting of the fp control word; 174 the value provided by the compiler assumes the widest setting. */ 175 #undef FLT_EVAL_METHOD 176 #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ 177 178 #endif /* C99 */ 179 180 181 /* Control word values for unNew (use with related unMask above) */ 182 #define _DN_SAVE 0x00000000 183 #define _DN_FLUSH 0x01000000 184 #define _DN_FLUSH_OPERANDS_SAVE_RESULTS 0x02000000 185 #define _DN_SAVE_OPERANDS_FLUSH_RESULTS 0x03000000 186 #define _EM_INVALID 0x00000010 187 #define _EM_DENORMAL 0x00080000 188 #define _EM_ZERODIVIDE 0x00000008 189 #define _EM_OVERFLOW 0x00000004 190 #define _EM_UNDERFLOW 0x00000002 191 #define _EM_INEXACT 0x00000001 192 #define _IC_AFFINE 0x00040000 193 #define _IC_PROJECTIVE 0x00000000 194 #define _RC_CHOP 0x00000300 195 #define _RC_UP 0x00000200 196 #define _RC_DOWN 0x00000100 197 #define _RC_NEAR 0x00000000 198 #define _PC_24 0x00020000 199 #define _PC_53 0x00010000 200 #define _PC_64 0x00000000 201 #define _EM_AMBIGUOUS 0x80000000 202 203 /* These are also defined in Mingw math.h, needed to work around 204 GCC build issues. */ 205 /* Return values for fpclass. */ 206 #ifndef __MINGW_FPCLASS_DEFINED 207 #define __MINGW_FPCLASS_DEFINED 1 208 #define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */ 209 #define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */ 210 #define _FPCLASS_NINF 0x0004 /* Negative Infinity */ 211 #define _FPCLASS_NN 0x0008 /* Negative Normal */ 212 #define _FPCLASS_ND 0x0010 /* Negative Denormal */ 213 #define _FPCLASS_NZ 0x0020 /* Negative Zero */ 214 #define _FPCLASS_PZ 0x0040 /* Positive Zero */ 215 #define _FPCLASS_PD 0x0080 /* Positive Denormal */ 216 #define _FPCLASS_PN 0x0100 /* Positive Normal */ 217 #define _FPCLASS_PINF 0x0200 /* Positive Infinity */ 218 #endif /* __MINGW_FPCLASS_DEFINED */ 219 220 /* _statusfp bit flags */ 221 #define _SW_INEXACT 0x00000001 /* inexact (precision) */ 222 #define _SW_UNDERFLOW 0x00000002 /* underflow */ 223 #define _SW_OVERFLOW 0x00000004 /* overflow */ 224 #define _SW_ZERODIVIDE 0x00000008 /* zero divide */ 225 #define _SW_INVALID 0x00000010 /* invalid */ 226 #define _SW_DENORMAL 0x00080000 /* denormal status bit */ 227 228 /* invalid subconditions (_SW_INVALID also set) */ 229 #define _SW_UNEMULATED 0x0040 /* unemulated instruction */ 230 #define _SW_SQRTNEG 0x0080 /* square root of a neg number */ 231 #define _SW_STACKOVERFLOW 0x0200 /* FP stack overflow */ 232 #define _SW_STACKUNDERFLOW 0x0400 /* FP stack underflow */ 233 234 /* Floating point error signals and return codes */ 235 #define _FPE_INVALID 0x81 236 #define _FPE_DENORMAL 0x82 237 #define _FPE_ZERODIVIDE 0x83 238 #define _FPE_OVERFLOW 0x84 239 #define _FPE_UNDERFLOW 0x85 240 #define _FPE_INEXACT 0x86 241 #define _FPE_UNEMULATED 0x87 242 #define _FPE_SQRTNEG 0x88 243 #define _FPE_STACKOVERFLOW 0x8a 244 #define _FPE_STACKUNDERFLOW 0x8b 245 #define _FPE_EXPLICITGEN 0x8c /* raise( SIGFPE ); */ 246 247 #ifndef __STRICT_ANSI__ 248 #define CW_DEFAULT _CW_DEFAULT 249 #define MCW_PC _MCW_PC 250 #define PC_24 _PC_24 251 #define PC_53 _PC_53 252 #define PC_64 _PC_64 253 #endif /* Not __STRICT_ANSI__ */ 254 255 #if defined(__i386__) 256 #define _CW_DEFAULT (_RC_NEAR+_PC_53+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL) 257 #elif defined(__ia64__) 258 #define _CW_DEFAULT (_RC_NEAR+_PC_64+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL) 259 #elif defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) 260 #define _CW_DEFAULT (_RC_NEAR+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL) 261 #endif 262 263 #ifndef RC_INVOKED 264 265 #ifdef __cplusplus 266 extern "C" { 267 #endif 268 269 /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask), 270 * i.e. change the bits in unMask to have the values they have in unNew, 271 * leaving other bits unchanged. */ 272 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int _NewValue, unsigned int _Mask) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 273 _SECIMP errno_t __cdecl _controlfp_s(unsigned int *_CurrentState, unsigned int _NewValue, unsigned int _Mask); 274 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _control87 (unsigned int _NewValue, unsigned int _Mask); 275 #ifdef __i386__ 276 _CRTIMP int __cdecl __control87_2(unsigned int, unsigned int, unsigned int *, unsigned int *); 277 #endif 278 279 280 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _clearfp (void); /* Clear the FPU status word */ 281 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _statusfp (void); /* Report the FPU status word */ 282 #define _clear87 _clearfp 283 #define _status87 _statusfp 284 285 286 /* 287 MSVCRT.dll _fpreset initializes the control register to 0x27f, 288 the status register to zero and the tag word to 0FFFFh. 289 This differs from asm instruction finit/fninit which set control 290 word to 0x37f (64 bit mantissa precison rather than 53 bit). 291 By default, the mingw version of _fpreset sets fp control as 292 per fninit. To use the MSVCRT.dll _fpreset, include CRT_fp8.o when 293 building your application. 294 */ 295 void __cdecl __MINGW_NOTHROW _fpreset (void); 296 #ifndef __STRICT_ANSI__ 297 void __cdecl __MINGW_NOTHROW fpreset (void); 298 #endif /* Not __STRICT_ANSI__ */ 299 300 /* Global 'variable' for the current floating point error code. */ 301 _CRTIMP int * __cdecl __MINGW_NOTHROW __fpecode(void); 302 #define _fpecode (*(__fpecode())) 303 304 /* 305 * IEEE recommended functions. MS puts them in float.h 306 * but they really belong in math.h. 307 */ 308 309 #ifndef _SIGN_DEFINED 310 #define _SIGN_DEFINED 311 _CRTIMP double __cdecl __MINGW_NOTHROW _chgsign (double _X); 312 _CRTIMP double __cdecl __MINGW_NOTHROW _copysign (double _Number,double _Sign); 313 _CRTIMP double __cdecl __MINGW_NOTHROW _logb (double); 314 _CRTIMP double __cdecl __MINGW_NOTHROW _nextafter (double, double); 315 _CRTIMP double __cdecl __MINGW_NOTHROW _scalb (double, long); 316 317 _CRTIMP int __cdecl __MINGW_NOTHROW _finite (double); 318 _CRTIMP int __cdecl __MINGW_NOTHROW _fpclass (double); 319 _CRTIMP int __cdecl __MINGW_NOTHROW _isnan (double); 320 321 #define _copysignl copysignl 322 extern long double __cdecl _chgsignl (long double); 323 #endif /* _SIGN_DEFINED */ 324 325 #ifdef __cplusplus 326 } 327 #endif 328 329 #endif /* Not RC_INVOKED */ 330 331 #endif /* _MINGW_FLOAT_H_ */ 332