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(_CRTBLD) || 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 _EM_INVALID 0x00000010
|
---|
185 | #define _EM_DENORMAL 0x00080000
|
---|
186 | #define _EM_ZERODIVIDE 0x00000008
|
---|
187 | #define _EM_OVERFLOW 0x00000004
|
---|
188 | #define _EM_UNDERFLOW 0x00000002
|
---|
189 | #define _EM_INEXACT 0x00000001
|
---|
190 | #define _IC_AFFINE 0x00040000
|
---|
191 | #define _IC_PROJECTIVE 0x00000000
|
---|
192 | #define _RC_CHOP 0x00000300
|
---|
193 | #define _RC_UP 0x00000200
|
---|
194 | #define _RC_DOWN 0x00000100
|
---|
195 | #define _RC_NEAR 0x00000000
|
---|
196 | #define _PC_24 0x00020000
|
---|
197 | #define _PC_53 0x00010000
|
---|
198 | #define _PC_64 0x00000000
|
---|
199 |
|
---|
200 | /* These are also defined in Mingw math.h, needed to work around
|
---|
201 | GCC build issues. */
|
---|
202 | /* Return values for fpclass. */
|
---|
203 | #ifndef __MINGW_FPCLASS_DEFINED
|
---|
204 | #define __MINGW_FPCLASS_DEFINED 1
|
---|
205 | #define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */
|
---|
206 | #define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */
|
---|
207 | #define _FPCLASS_NINF 0x0004 /* Negative Infinity */
|
---|
208 | #define _FPCLASS_NN 0x0008 /* Negative Normal */
|
---|
209 | #define _FPCLASS_ND 0x0010 /* Negative Denormal */
|
---|
210 | #define _FPCLASS_NZ 0x0020 /* Negative Zero */
|
---|
211 | #define _FPCLASS_PZ 0x0040 /* Positive Zero */
|
---|
212 | #define _FPCLASS_PD 0x0080 /* Positive Denormal */
|
---|
213 | #define _FPCLASS_PN 0x0100 /* Positive Normal */
|
---|
214 | #define _FPCLASS_PINF 0x0200 /* Positive Infinity */
|
---|
215 | #endif /* __MINGW_FPCLASS_DEFINED */
|
---|
216 |
|
---|
217 | /* invalid subconditions (_SW_INVALID also set) */
|
---|
218 | #define _SW_UNEMULATED 0x0040 /* unemulated instruction */
|
---|
219 | #define _SW_SQRTNEG 0x0080 /* square root of a neg number */
|
---|
220 | #define _SW_STACKOVERFLOW 0x0200 /* FP stack overflow */
|
---|
221 | #define _SW_STACKUNDERFLOW 0x0400 /* FP stack underflow */
|
---|
222 |
|
---|
223 | /* Floating point error signals and return codes */
|
---|
224 | #define _FPE_INVALID 0x81
|
---|
225 | #define _FPE_DENORMAL 0x82
|
---|
226 | #define _FPE_ZERODIVIDE 0x83
|
---|
227 | #define _FPE_OVERFLOW 0x84
|
---|
228 | #define _FPE_UNDERFLOW 0x85
|
---|
229 | #define _FPE_INEXACT 0x86
|
---|
230 | #define _FPE_UNEMULATED 0x87
|
---|
231 | #define _FPE_SQRTNEG 0x88
|
---|
232 | #define _FPE_STACKOVERFLOW 0x8a
|
---|
233 | #define _FPE_STACKUNDERFLOW 0x8b
|
---|
234 | #define _FPE_EXPLICITGEN 0x8c /* raise( SIGFPE ); */
|
---|
235 |
|
---|
236 | #ifndef __STRICT_ANSI__
|
---|
237 | #define CW_DEFAULT _CW_DEFAULT
|
---|
238 | #define MCW_PC _MCW_PC
|
---|
239 | #define PC_24 _PC_24
|
---|
240 | #define PC_53 _PC_53
|
---|
241 | #define PC_64 _PC_64
|
---|
242 | #endif /* Not __STRICT_ANSI__ */
|
---|
243 |
|
---|
244 | #if defined(__i386__)
|
---|
245 | #define _CW_DEFAULT (_RC_NEAR+_PC_53+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
|
---|
246 | #elif defined(__ia64__)
|
---|
247 | #define _CW_DEFAULT (_RC_NEAR+_PC_64+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
|
---|
248 | #elif defined(__x86_64__)
|
---|
249 | #define _CW_DEFAULT (_RC_NEAR+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
|
---|
250 | #endif
|
---|
251 |
|
---|
252 | #ifndef RC_INVOKED
|
---|
253 |
|
---|
254 | #ifdef __cplusplus
|
---|
255 | extern "C" {
|
---|
256 | #endif
|
---|
257 |
|
---|
258 | /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
|
---|
259 | * i.e. change the bits in unMask to have the values they have in unNew,
|
---|
260 | * leaving other bits unchanged. */
|
---|
261 | _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int _NewValue, unsigned int _Mask) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
|
---|
262 | _SECIMP errno_t __cdecl _controlfp_s(unsigned int *_CurrentState, unsigned int _NewValue, unsigned int _Mask);
|
---|
263 | _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _control87 (unsigned int _NewValue, unsigned int _Mask);
|
---|
264 |
|
---|
265 |
|
---|
266 | _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _clearfp (void); /* Clear the FPU status word */
|
---|
267 | _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _statusfp (void); /* Report the FPU status word */
|
---|
268 | #define _clear87 _clearfp
|
---|
269 | #define _status87 _statusfp
|
---|
270 |
|
---|
271 |
|
---|
272 | /*
|
---|
273 | MSVCRT.dll _fpreset initializes the control register to 0x27f,
|
---|
274 | the status register to zero and the tag word to 0FFFFh.
|
---|
275 | This differs from asm instruction finit/fninit which set control
|
---|
276 | word to 0x37f (64 bit mantissa precison rather than 53 bit).
|
---|
277 | By default, the mingw version of _fpreset sets fp control as
|
---|
278 | per fninit. To use the MSVCRT.dll _fpreset, include CRT_fp8.o when
|
---|
279 | building your application.
|
---|
280 | */
|
---|
281 | void __cdecl __MINGW_NOTHROW _fpreset (void);
|
---|
282 | #ifndef __STRICT_ANSI__
|
---|
283 | void __cdecl __MINGW_NOTHROW fpreset (void);
|
---|
284 | #endif /* Not __STRICT_ANSI__ */
|
---|
285 |
|
---|
286 | /* Global 'variable' for the current floating point error code. */
|
---|
287 | _CRTIMP int * __cdecl __MINGW_NOTHROW __fpecode(void);
|
---|
288 | #define _fpecode (*(__fpecode()))
|
---|
289 |
|
---|
290 | /*
|
---|
291 | * IEEE recommended functions. MS puts them in float.h
|
---|
292 | * but they really belong in math.h.
|
---|
293 | */
|
---|
294 |
|
---|
295 | #ifndef _SIGN_DEFINED
|
---|
296 | #define _SIGN_DEFINED
|
---|
297 | _CRTIMP double __cdecl __MINGW_NOTHROW _chgsign (double _X);
|
---|
298 | _CRTIMP double __cdecl __MINGW_NOTHROW _copysign (double _Number,double _Sign);
|
---|
299 | _CRTIMP double __cdecl __MINGW_NOTHROW _logb (double);
|
---|
300 | _CRTIMP double __cdecl __MINGW_NOTHROW _nextafter (double, double);
|
---|
301 | _CRTIMP double __cdecl __MINGW_NOTHROW _scalb (double, long);
|
---|
302 |
|
---|
303 | _CRTIMP int __cdecl __MINGW_NOTHROW _finite (double);
|
---|
304 | _CRTIMP int __cdecl __MINGW_NOTHROW _fpclass (double);
|
---|
305 | _CRTIMP int __cdecl __MINGW_NOTHROW _isnan (double);
|
---|
306 |
|
---|
307 | #define _copysignl copysignl
|
---|
308 | extern long double __cdecl _chgsignl (long double);
|
---|
309 | #endif /* _SIGN_DEFINED */
|
---|
310 |
|
---|
311 | #ifdef __cplusplus
|
---|
312 | }
|
---|
313 | #endif
|
---|
314 |
|
---|
315 | #endif /* Not RC_INVOKED */
|
---|
316 |
|
---|
317 | #endif /* _MINGW_FLOAT_H_ */
|
---|
318 |
|
---|