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 	#define _FLOAT_H___
123 #endif
124 #endif
125 #endif
126 
127 #ifndef _MINGW_FLOAT_H_
128 #define _MINGW_FLOAT_H_
129 
130 /* All the headers include this file. */
131 #include <crtdefs.h>
132 
133 /*
134  * Functions and definitions for controlling the FPU.
135  */
136 #ifndef	__STRICT_ANSI__
137 
138 /* TODO: These constants are only valid for x86 machines */
139 
140 /* Control word masks for unMask */
141 #define	_MCW_DN  	0x03000000  	/* Denormal control */
142 #define	_MCW_EM		0x0008001F	/* Error masks */
143 #define	_MCW_IC		0x00040000	/* Infinity */
144 #define	_MCW_RC		0x00000300	/* Rounding */
145 #define	_MCW_PC		0x00030000	/* Precision */
146 
147 /* Number of base-FLT_RADIX digits in the significand, p.  */
148 #undef FLT_MANT_DIG
149 #undef DBL_MANT_DIG
150 #undef LDBL_MANT_DIG
151 #define FLT_MANT_DIG   __FLT_MANT_DIG__
152 #define DBL_MANT_DIG   __DBL_MANT_DIG__
153 #define LDBL_MANT_DIG  __LDBL_MANT_DIG__
154 
155 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
156 /* The floating-point expression evaluation method.
157       -1  indeterminate
158        0  evaluate all operations and constants just to the range and
159 	  precision of the type
160        1  evaluate operations and constants of type float and double
161 	  to the range and precision of the double type, evaluate
162 	  long double operations and constants to the range and
163 	  precision of the long double type
164        2  evaluate all operations and constants to the range and
165 	  precision of the long double type
166 
167    ??? This ought to change with the setting of the fp control word;
168    the value provided by the compiler assumes the widest setting.  */
169 #undef FLT_EVAL_METHOD
170 #define FLT_EVAL_METHOD	__FLT_EVAL_METHOD__
171 
172 #endif /* C99 */
173 
174 
175 /* Control word values for unNew (use with related unMask above) */
176 #define	_DN_SAVE	0x00000000
177 #define	_DN_FLUSH	0x01000000
178 #define	_EM_INVALID	0x00000010
179 #define	_EM_DENORMAL	0x00080000
180 #define	_EM_ZERODIVIDE	0x00000008
181 #define	_EM_OVERFLOW	0x00000004
182 #define	_EM_UNDERFLOW	0x00000002
183 #define	_EM_INEXACT	0x00000001
184 #define	_IC_AFFINE	0x00040000
185 #define	_IC_PROJECTIVE	0x00000000
186 #define	_RC_CHOP	0x00000300
187 #define	_RC_UP		0x00000200
188 #define	_RC_DOWN	0x00000100
189 #define	_RC_NEAR	0x00000000
190 #define	_PC_24		0x00020000
191 #define	_PC_53		0x00010000
192 #define	_PC_64		0x00000000
193 
194 /* These are also defined in Mingw math.h, needed to work around
195    GCC build issues.  */
196 /* Return values for fpclass. */
197 #ifndef __MINGW_FPCLASS_DEFINED
198 #define __MINGW_FPCLASS_DEFINED 1
199 #define	_FPCLASS_SNAN	0x0001	/* Signaling "Not a Number" */
200 #define	_FPCLASS_QNAN	0x0002	/* Quiet "Not a Number" */
201 #define	_FPCLASS_NINF	0x0004	/* Negative Infinity */
202 #define	_FPCLASS_NN	0x0008	/* Negative Normal */
203 #define	_FPCLASS_ND	0x0010	/* Negative Denormal */
204 #define	_FPCLASS_NZ	0x0020	/* Negative Zero */
205 #define	_FPCLASS_PZ	0x0040	/* Positive Zero */
206 #define	_FPCLASS_PD	0x0080	/* Positive Denormal */
207 #define	_FPCLASS_PN	0x0100	/* Positive Normal */
208 #define	_FPCLASS_PINF	0x0200	/* Positive Infinity */
209 #endif /* __MINGW_FPCLASS_DEFINED */
210 
211 /* invalid subconditions (_SW_INVALID also set) */
212 #define _SW_UNEMULATED		0x0040  /* unemulated instruction */
213 #define _SW_SQRTNEG		0x0080  /* square root of a neg number */
214 #define _SW_STACKOVERFLOW	0x0200  /* FP stack overflow */
215 #define _SW_STACKUNDERFLOW	0x0400  /* FP stack underflow */
216 
217 /*  Floating point error signals and return codes */
218 #define _FPE_INVALID		0x81
219 #define _FPE_DENORMAL		0x82
220 #define _FPE_ZERODIVIDE		0x83
221 #define _FPE_OVERFLOW		0x84
222 #define _FPE_UNDERFLOW		0x85
223 #define _FPE_INEXACT		0x86
224 #define _FPE_UNEMULATED		0x87
225 #define _FPE_SQRTNEG		0x88
226 #define _FPE_STACKOVERFLOW	0x8a
227 #define _FPE_STACKUNDERFLOW	0x8b
228 #define _FPE_EXPLICITGEN	0x8c    /* raise( SIGFPE ); */
229 
230 #define CW_DEFAULT _CW_DEFAULT
231 #define MCW_PC  _MCW_PC
232 #define PC_24   _PC_24
233 #define PC_53   _PC_53
234 #define PC_64   _PC_64
235 
236 #if defined(_M_IX86)
237 #define _CW_DEFAULT (_RC_NEAR+_PC_53+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
238 #elif defined(_M_IA64)
239 #define _CW_DEFAULT (_RC_NEAR+_PC_64+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
240 #elif defined(_M_AMD64)
241 #define _CW_DEFAULT (_RC_NEAR+_EM_INVALID+_EM_ZERODIVIDE+_EM_OVERFLOW+_EM_UNDERFLOW+_EM_INEXACT+_EM_DENORMAL)
242 #endif
243 
244 #ifndef RC_INVOKED
245 
246 #ifdef	__cplusplus
247 extern "C" {
248 #endif
249 
250 /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
251  * i.e. change the bits in unMask to have the values they have in unNew,
252  * leaving other bits unchanged. */
253 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int unNew, unsigned int unMask) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
254 _SECIMP errno_t __cdecl _controlfp_s(unsigned int *_CurrentState, unsigned int _NewValue, unsigned int _Mask);
255 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _control87 (unsigned int unNew, unsigned int unMask);
256 
257 
258 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _clearfp (void);	/* Clear the FPU status word */
259 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _statusfp (void);	/* Report the FPU status word */
260 #define		_clear87	_clearfp
261 #define		_status87	_statusfp
262 
263 
264 /*
265    MSVCRT.dll _fpreset initializes the control register to 0x27f,
266    the status register to zero and the tag word to 0FFFFh.
267    This differs from asm instruction finit/fninit which set control
268    word to 0x37f (64 bit mantissa precison rather than 53 bit).
269    By default, the mingw version of _fpreset sets fp control as
270    per fninit. To use the MSVCRT.dll _fpreset, include CRT_fp8.o when
271    building your application.
272 */
273 void __cdecl __MINGW_NOTHROW _fpreset (void);
274 void __cdecl __MINGW_NOTHROW fpreset (void);
275 
276 /* Global 'variable' for the current floating point error code. */
277 _CRTIMP int * __cdecl __MINGW_NOTHROW __fpecode(void);
278 #define	_fpecode	(*(__fpecode()))
279 
280 /*
281  * IEEE recommended functions.  MS puts them in float.h
282  * but they really belong in math.h.
283  */
284 
285 #ifndef _SIGN_DEFINED
286 #define _SIGN_DEFINED
287 _CRTIMP double __cdecl __MINGW_NOTHROW _chgsign (double _X);
288 _CRTIMP double __cdecl __MINGW_NOTHROW _copysign (double _Number,double _Sign);
289 _CRTIMP double __cdecl __MINGW_NOTHROW _logb (double);
290 _CRTIMP double __cdecl __MINGW_NOTHROW _nextafter (double, double);
291 _CRTIMP double __cdecl __MINGW_NOTHROW _scalb (double, long);
292 
293 _CRTIMP int __cdecl __MINGW_NOTHROW _finite (double);
294 _CRTIMP int __cdecl __MINGW_NOTHROW _fpclass (double);
295 _CRTIMP int __cdecl __MINGW_NOTHROW _isnan (double);
296 
297 #define _copysignl copysignl
298 extern long double __cdecl _chgsignl (long double);
299 #endif /* _SIGN_DEFINED */
300 
301 #ifdef	__cplusplus
302 }
303 #endif
304 
305 #endif	/* Not RC_INVOKED */
306 
307 #endif	/* Not __STRICT_ANSI__ */
308 
309 #endif /* _MINGW_FLOAT_H_ */
310 
311