xref: /reactos/sdk/include/crt/float.h (revision 84344399)
1 /*
2  * float.h
3  * This file has no copyright assigned and is placed in the Public Domain.
4  * This file is a part of the mingw-runtime package.
5  * No warranty is given; refer to the file DISCLAIMER 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  * NOTE: GCC provides float.h, but it doesn't include the non-standard
13  *       stuff for accessing the fp controller. We include_next the
14  *       GCC-supplied header and just define the MS-specific extensions
15  *       here.
16  *
17  */
18 
19 #ifndef _MINGW_FLOAT_H_
20 #define _MINGW_FLOAT_H_
21 
22 #if defined(__GNUC__)
23 #include "mingw32/gcc_float.h"
24 #elif defined(_MSC_VER)
25 #include "msc/msc_float.h"
26 #else
27 #error
28 #endif
29 
30 #include <corecrt.h>
31 
32 /*
33  * Functions and definitions for controlling the FPU.
34  */
35 #ifndef	__STRICT_ANSI__
36 
37 /* TODO: These constants are only valid for x86 machines */
38 
39 /* Control word masks for unMask */
40 #define	_MCW_EM		0x0008001F	/* Error masks */
41 #define	_MCW_IC		0x00040000	/* Infinity */
42 #define	_MCW_RC		0x00000300	/* Rounding */
43 #define	_MCW_PC		0x00030000	/* Precision */
44 #define _MCW_DN     0x03000000  /* Denormal */
45 
46 /* Control word values for unNew (use with related unMask above) */
47 #define	_EM_INVALID	0x00000010
48 #define	_EM_DENORMAL	0x00080000
49 #define	_EM_ZERODIVIDE	0x00000008
50 #define	_EM_OVERFLOW	0x00000004
51 #define	_EM_UNDERFLOW	0x00000002
52 #define	_EM_INEXACT	0x00000001
53 #define	_IC_AFFINE	0x00040000
54 #define	_IC_PROJECTIVE	0x00000000
55 #define	_RC_CHOP	0x00000300
56 #define	_RC_UP		0x00000200
57 #define	_RC_DOWN	0x00000100
58 #define	_RC_NEAR	0x00000000
59 #define	_PC_24		0x00020000
60 #define	_PC_53		0x00010000
61 #define	_PC_64		0x00000000
62 #define _DN_SAVE	0x00000000
63 #define _DN_FLUSH	0x01000000
64 #define _DN_FLUSH_OPERANDS_SAVE_RESULTS 0x02000000
65 #define _DN_SAVE_OPERANDS_FLUSH_RESULTS 0x03000000
66 
67 /* These are also defined in Mingw math.h, needed to work around
68    GCC build issues.  */
69 /* Return values for fpclass. */
70 #ifndef __MINGW_FPCLASS_DEFINED
71 #define __MINGW_FPCLASS_DEFINED 1
72 #define	_FPCLASS_SNAN	0x0001	/* Signaling "Not a Number" */
73 #define	_FPCLASS_QNAN	0x0002	/* Quiet "Not a Number" */
74 #define	_FPCLASS_NINF	0x0004	/* Negative Infinity */
75 #define	_FPCLASS_NN	0x0008	/* Negative Normal */
76 #define	_FPCLASS_ND	0x0010	/* Negative Denormal */
77 #define	_FPCLASS_NZ	0x0020	/* Negative Zero */
78 #define	_FPCLASS_PZ	0x0040	/* Positive Zero */
79 #define	_FPCLASS_PD	0x0080	/* Positive Denormal */
80 #define	_FPCLASS_PN	0x0100	/* Positive Normal */
81 #define	_FPCLASS_PINF	0x0200	/* Positive Infinity */
82 #endif /* __MINGW_FPCLASS_DEFINED */
83 
84 /* _statusfp bit flags */
85 #define _SW_INEXACT    0x00000001  /* inexact (precision) */
86 #define _SW_UNDERFLOW  0x00000002  /* underflow */
87 #define _SW_OVERFLOW   0x00000004  /* overflow */
88 #define _SW_ZERODIVIDE 0x00000008  /* zero divide */
89 #define _SW_INVALID    0x00000010  /* invalid */
90 #define _SW_DENORMAL   0x00080000  /* denormal status bit */
91 
92 /* invalid subconditions (_SW_INVALID also set) */
93 #define _SW_UNEMULATED		0x0040  /* unemulated instruction */
94 #define _SW_SQRTNEG		0x0080  /* square root of a neg number */
95 #define _SW_STACKOVERFLOW	0x0200  /* FP stack overflow */
96 #define _SW_STACKUNDERFLOW	0x0400  /* FP stack underflow */
97 
98 /*  Floating point error signals and return codes */
99 #define _FPE_INVALID		0x81
100 #define _FPE_DENORMAL		0x82
101 #define _FPE_ZERODIVIDE		0x83
102 #define _FPE_OVERFLOW		0x84
103 #define _FPE_UNDERFLOW		0x85
104 #define _FPE_INEXACT		0x86
105 #define _FPE_UNEMULATED		0x87
106 #define _FPE_SQRTNEG		0x88
107 #define _FPE_STACKOVERFLOW	0x8a
108 #define _FPE_STACKUNDERFLOW	0x8b
109 #define _FPE_EXPLICITGEN	0x8c    /* raise( SIGFPE ); */
110 
111 #ifndef RC_INVOKED
112 
113 #ifdef	__cplusplus
114 extern "C" {
115 #endif
116 
117 /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
118  * i.e. change the bits in unMask to have the values they have in unNew,
119  * leaving other bits unchanged. */
120 
121 __MINGW_NOTHROW
122 _CRTIMP
123 unsigned int
124 __cdecl
125 _controlfp(
126   _In_ unsigned int unNew,
127   _In_ unsigned int unMask);
128 
129 __MINGW_NOTHROW
130 _CRTIMP
131 unsigned int
132 __cdecl
133 _control87(
134   _In_ unsigned int unNew,
135   _In_ unsigned int unMask);
136 
137 __MINGW_NOTHROW _CRTIMP unsigned int __cdecl _clearfp (void);	/* Clear the FPU status word */
138 __MINGW_NOTHROW _CRTIMP unsigned int __cdecl _statusfp (void);	/* Report the FPU status word */
139 #define		_clear87	_clearfp
140 #define		_status87	_statusfp
141 
142 
143 /*
144    MSVCRT.dll _fpreset initializes the control register to 0x27f,
145    the status register to zero and the tag word to 0FFFFh.
146    This differs from asm instruction finit/fninit which set control
147    word to 0x37f (64 bit mantissa precison rather than 53 bit).
148    By default, the mingw version of _fpreset sets fp control as
149    per fninit. To use the MSVCRT.dll _fpreset, include CRT_fp8.o when
150    building your application.
151 */
152 __MINGW_NOTHROW void __cdecl _fpreset (void);
153 __MINGW_NOTHROW void __cdecl fpreset (void);
154 
155 /* Global 'variable' for the current floating point error code. */
156 __MINGW_NOTHROW _CRTIMP int * __cdecl __fpecode(void);
157 #define	_fpecode	(*(__fpecode()))
158 
159 /*
160  * IEEE recommended functions.  MS puts them in float.h
161  * but they really belong in math.h.
162  */
163 
164 _Check_return_
165 __MINGW_NOTHROW
166 _CRTIMP
167 double
168 __cdecl
169 _chgsign(
170   _In_ double);
171 
172 _Check_return_
173 __MINGW_NOTHROW
174 _CRTIMP
175 double
176 __cdecl
177 _copysign(
178   _In_ double,
179   _In_ double);
180 
181 _Check_return_
182 __MINGW_NOTHROW
183 _CRTIMP
184 double
185 __cdecl
186 _logb(
187   _In_ double);
188 
189 _Check_return_
190 __MINGW_NOTHROW
191 _CRTIMP
192 double
193 __cdecl
194 _nextafter(
195   _In_ double,
196   _In_ double);
197 
198 _Check_return_
199 __MINGW_NOTHROW
200 _CRTIMP
201 double
202 __cdecl
203 _scalb(
204   _In_ double,
205   _In_ long);
206 
207 _Check_return_
208 __MINGW_NOTHROW
209 _CRTIMP
210 int
211 __cdecl
212 _finite(
213   _In_ double);
214 
215 _Check_return_
216 __MINGW_NOTHROW
217 _CRTIMP
218 int
219 __cdecl
220 _fpclass(
221   _In_ double);
222 
223 _Check_return_
224 __MINGW_NOTHROW
225 _CRTIMP
226 int
227 __cdecl
228 _isnan(
229   _In_ double);
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 #endif	/* Not RC_INVOKED */
236 
237 #endif	/* Not __STRICT_ANSI__ */
238 
239 #endif /* _MINGW_FLOAT_H_ */
240