OSDN Git Service

_USE_32BIT_TIME_T resolution and prepare for release.
[mingw/mingw-org-wsl.git] / include / float.h
1 /**
2  * @file float.h
3  * @copy 2012 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 #ifndef _MINGW_FLOAT_H_
25 #define _MINGW_FLOAT_H_
26 #pragma GCC system_header
27 #include <_mingw.h>
28
29 /* 
30  * Constants related to floating point arithmetic.
31  *
32  * Also included here are some non-ANSI bits for accessing the floating
33  * point controller.
34  *
35  * NOTE:
36  *
37  * GCC provides float.h, but it doesn't include the non-standard stuff for
38  * accessing the fp controller.  We parse the GCC-supplied header, for its
39  * standard content, and then define the MS-specific extensions here.
40  *
41  * In a MinGW standard Win32 hosted environment, this should be the float.h
42  * found by a system include path search, but this can't be guaranteed; for
43  * a cross-compiler setup, the GCC-supplied header, which is guarded by the
44  * _FLOAT_H___ macro, may be found first, thus...
45  *
46  */
47 #if !defined(_FLOAT_H___) && !defined(__FLOAT_H)
48
49  /*
50   * ...when we didn't find the GCC-supplied header first, we want to pull
51   * it in now; include_next should achieve this, (and we must rely on the
52   * GCC header maintainers to extend us the same courtesy, to get this one
53   * pulled in, when the GCC-supplied header is found first).
54   *
55   */
56 # include_next <float.h>
57 #endif
58
59 /*
60  * Functions and definitions for controlling the FPU.
61  */
62 #ifndef __STRICT_ANSI__
63
64 /* TODO: These constants are only valid for x86 machines */
65
66 /* Control word masks for unMask */
67 #define _MCW_EM         0x0008001F      /* Error masks */
68 #define _MCW_IC         0x00040000      /* Infinity */
69 #define _MCW_RC         0x00000300      /* Rounding */
70 #define _MCW_PC         0x00030000      /* Precision */
71
72 /* Control word values for unNew (use with related unMask above) */
73 #define _EM_INVALID     0x00000010
74 #define _EM_DENORMAL    0x00080000
75 #define _EM_ZERODIVIDE  0x00000008
76 #define _EM_OVERFLOW    0x00000004
77 #define _EM_UNDERFLOW   0x00000002
78 #define _EM_INEXACT     0x00000001
79 #define _IC_AFFINE      0x00040000
80 #define _IC_PROJECTIVE  0x00000000
81 #define _RC_CHOP        0x00000300
82 #define _RC_UP          0x00000200
83 #define _RC_DOWN        0x00000100
84 #define _RC_NEAR        0x00000000
85 #define _PC_24          0x00020000
86 #define _PC_53          0x00010000
87 #define _PC_64          0x00000000
88
89 /* These are also defined in Mingw math.h, needed to work around
90    GCC build issues.  */
91 /* Return values for fpclass. */
92 #ifndef __MINGW_FPCLASS_DEFINED
93 #define __MINGW_FPCLASS_DEFINED 1
94 #define _FPCLASS_SNAN   0x0001  /* Signaling "Not a Number" */
95 #define _FPCLASS_QNAN   0x0002  /* Quiet "Not a Number" */
96 #define _FPCLASS_NINF   0x0004  /* Negative Infinity */
97 #define _FPCLASS_NN     0x0008  /* Negative Normal */
98 #define _FPCLASS_ND     0x0010  /* Negative Denormal */
99 #define _FPCLASS_NZ     0x0020  /* Negative Zero */
100 #define _FPCLASS_PZ     0x0040  /* Positive Zero */
101 #define _FPCLASS_PD     0x0080  /* Positive Denormal */
102 #define _FPCLASS_PN     0x0100  /* Positive Normal */
103 #define _FPCLASS_PINF   0x0200  /* Positive Infinity */
104 #endif /* __MINGW_FPCLASS_DEFINED */
105
106 /* invalid subconditions (_SW_INVALID also set) */
107 #define _SW_UNEMULATED          0x0040  /* unemulated instruction */
108 #define _SW_SQRTNEG             0x0080  /* square root of a neg number */
109 #define _SW_STACKOVERFLOW       0x0200  /* FP stack overflow */
110 #define _SW_STACKUNDERFLOW      0x0400  /* FP stack underflow */
111
112 /*  Floating point error signals and return codes */
113 #define _FPE_INVALID            0x81
114 #define _FPE_DENORMAL           0x82
115 #define _FPE_ZERODIVIDE         0x83
116 #define _FPE_OVERFLOW           0x84
117 #define _FPE_UNDERFLOW          0x85
118 #define _FPE_INEXACT            0x86
119 #define _FPE_UNEMULATED         0x87
120 #define _FPE_SQRTNEG            0x88
121 #define _FPE_STACKOVERFLOW      0x8a
122 #define _FPE_STACKUNDERFLOW     0x8b
123 #define _FPE_EXPLICITGEN        0x8c    /* raise( SIGFPE ); */
124
125 #ifndef RC_INVOKED
126
127 #ifdef  __cplusplus
128 extern "C" {
129 #endif
130
131 /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
132  * i.e. change the bits in unMask to have the values they have in unNew,
133  * leaving other bits unchanged. */
134 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int unNew, unsigned int unMask);
135 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _control87 (unsigned int unNew, unsigned int unMask);
136
137
138 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _clearfp (void);   /* Clear the FPU status word */
139 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _statusfp (void);  /* Report the FPU status word */
140 #define         _clear87        _clearfp
141 #define         _status87       _statusfp
142
143
144 /*
145    MSVCRT.dll _fpreset initializes the control register to 0x27f,
146    the status register to zero and the tag word to 0FFFFh.
147    This differs from asm instruction finit/fninit which set control
148    word to 0x37f (64 bit mantissa precison rather than 53 bit).
149    By default, the mingw version of _fpreset sets fp control as
150    per fninit. To use the MSVCRT.dll _fpreset, include CRT_fp8.o when
151    building your application.    
152 */
153 void __cdecl __MINGW_NOTHROW _fpreset (void);
154 void __cdecl __MINGW_NOTHROW fpreset (void);
155
156 /* Global 'variable' for the current floating point error code. */
157 _CRTIMP int * __cdecl __MINGW_NOTHROW __fpecode(void);
158 #define _fpecode        (*(__fpecode()))
159
160 /*
161  * IEEE recommended functions.  MS puts them in float.h
162  * but they really belong in math.h.
163  */
164
165 _CRTIMP double __cdecl __MINGW_NOTHROW _chgsign (double);
166 _CRTIMP double __cdecl __MINGW_NOTHROW _copysign (double, double);
167 _CRTIMP double __cdecl __MINGW_NOTHROW _logb (double);
168 _CRTIMP double __cdecl __MINGW_NOTHROW _nextafter (double, double);
169 _CRTIMP double __cdecl __MINGW_NOTHROW _scalb (double, long);
170
171 _CRTIMP int __cdecl __MINGW_NOTHROW _finite (double);
172 _CRTIMP int __cdecl __MINGW_NOTHROW _fpclass (double);
173 _CRTIMP int __cdecl __MINGW_NOTHROW _isnan (double);
174
175 #ifdef  __cplusplus
176 }
177 #endif
178
179 #endif  /* Not RC_INVOKED */
180
181 #endif  /* Not __STRICT_ANSI__ */
182
183 #endif /* _MINGW_FLOAT_H_ */
184