58e4fdffcbd6a3e02fbe629ed3a114e95d50bf9e
[reactos.git] / include / msvcrt / float.h
1 /* 
2  * float.h
3  *
4  * Constants related to floating point arithmetic.
5  *
6  * Also included here are some non-ANSI bits for accessing the floating
7  * point controller.
8  *
9  * NOTE: GCC provides float.h, and it is probably more accurate than this,
10  *       but it doesn't include the non-standard stuff for accessing the
11  *       fp controller. (TODO: Move those bits elsewhere?) Thus it is
12  *       probably not a good idea to use the GCC supplied version instead
13  *       of this header.
14  *
15  * This file is part of the Mingw32 package.
16  *
17  * Contributors:
18  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
19  *
20  *  THIS SOFTWARE IS NOT COPYRIGHTED
21  *
22  *  This source code is offered for use in the public domain. You may
23  *  use, modify or distribute it freely.
24  *
25  *  This code is distributed in the hope that it will be useful but
26  *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
27  *  DISCLAIMED. This includes but is not limited to warranties of
28  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * $Revision$
31  * $Author$
32  * $Date$
33  *
34  */
35
36 #ifndef _FLOAT_H_
37 #define _FLOAT_H_
38
39
40 #define FLT_ROUNDS      1
41 #define FLT_GUARD       1
42 #define FLT_NORMALIZE   1
43
44 /*
45  * The characteristics of float.
46  */
47
48 /* The radix for floating point representation. */
49 #define FLT_RADIX       2
50
51 /* Decimal digits of precision. */
52 #define FLT_DIG         6
53
54 /* Smallest number such that 1+x != 1 */
55 #define FLT_EPSILON     1.19209290e-07F
56
57 /* The number of base FLT_RADIX digits in the mantissa. */
58 #define FLT_MANT_DIG    24
59
60 /* The maximum floating point number. */
61 #define FLT_MAX         3.40282347e+38F
62
63 /* Maximum n such that FLT_RADIX^n - 1 is representable. */
64 #define FLT_MAX_EXP     128
65
66 /* Maximum n such that 10^n is representable. */
67 #define FLT_MAX_10_EXP  38
68
69 /* Minimum normalized floating-point number. */
70 #define FLT_MIN         1.17549435e-38F
71
72 /* Minimum n such that FLT_RADIX^n is a normalized number. */
73 #define FLT_MIN_EXP     (-125)
74
75 /* Minimum n such that 10^n is a normalized number. */
76 #define FLT_MIN_10_EXP  (-37)
77
78
79 /*
80  * The characteristics of double.
81  */
82 #define DBL_DIG         15
83 #define DBL_EPSILON     1.1102230246251568e-16
84 #define DBL_MANT_DIG    53
85 #define DBL_MAX         1.7976931348623157e+308
86 #define DBL_MAX_EXP     1024
87 #define DBL_MAX_10_EXP  308
88 #define DBL_MIN         2.2250738585072014e-308
89 #define DBL_MIN_EXP     (-1021)
90 #define DBL_MIN_10_EXP  (-307)
91
92
93 /*
94  * The characteristics of long double.
95  * NOTE: long double is the same as double.
96  */
97 #define LDBL_DIG        15
98 #define LDBL_EPSILON    1.1102230246251568e-16L
99 #define LDBL_MANT_DIG   53
100 #define LDBL_MAX        1.7976931348623157e+308L
101 #define LDBL_MAX_EXP    1024
102 #define LDBL_MAX_10_EXP 308
103 #define LDBL_MIN        2.2250738585072014e-308L
104 #define LDBL_MIN_EXP    (-1021)
105 #define LDBL_MIN_10_EXP (-307)
106
107
108 /*
109  * Functions and definitions for controlling the FPU.
110  */
111 #ifndef __STRICT_ANSI__
112
113 /* TODO: These constants are only valid for x86 machines */
114
115 /* Control word masks for unMask */
116 #define _MCW_EM         0x0008001F      /* Error masks */
117 #define _MCW_IC         0x00040000      /* Infinity */
118 #define _MCW_RC         0x00000300      /* Rounding */
119 #define _MCW_PC         0x00030000      /* Precision */
120
121 /* Control word values for unNew (use with related unMask above) */
122 #define _EM_INVALID     0x00000010
123 #define _EM_DENORMAL    0x00080000
124 #define _EM_ZERODIVIDE  0x00000008
125 #define _EM_OVERFLOW    0x00000004
126 #define _EM_UNDERFLOW   0x00000002
127 #define _EM_INEXACT     0x00000001
128 #define _IC_AFFINE      0x00040000
129 #define _IC_PROJECTIVE  0x00000000
130 #define _RC_CHOP        0x00000300
131 #define _RC_UP          0x00000200
132 #define _RC_DOWN        0x00000100
133 #define _RC_NEAR        0x00000000
134 #define _PC_24          0x00020000
135 #define _PC_53          0x00010000
136 #define _PC_64          0x00000000
137
138 /* Return values for fpclass. */
139 #define _FPCLASS_SNAN   0x0001  /* Signaling "Not a Number" */
140 #define _FPCLASS_QNAN   0x0002  /* Quiet "Not a Number" */
141 #define _FPCLASS_NINF   0x0004  /* Negative Infinity */
142 #define _FPCLASS_NN     0x0008  /* Negative Normal */
143 #define _FPCLASS_ND     0x0010  /* Negative Denormal */
144 #define _FPCLASS_NZ     0x0020  /* Negative Zero */
145 #define _FPCLASS_PZ     0x0040  /* Positive Zero */
146 #define _FPCLASS_PD     0x0080  /* Positive Denormal */
147 #define _FPCLASS_PN     0x0100  /* Positive Normal */
148 #define _FPCLASS_PINF   0x0200  /* Positive Infinity */
149
150
151 #ifdef  __cplusplus
152 extern "C" {
153 #endif
154
155
156 /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
157  * i.e. change the bits in unMask to have the values they have in unNew,
158  * leaving other bits unchanged. */
159 unsigned int    _controlfp(unsigned int unNew, unsigned int unMask);
160 unsigned int    _control87(unsigned int unNew, unsigned int unMask);
161
162
163 unsigned int    _clearfp(void);        /* Clear the FPU status word */
164 unsigned int    _statusfp(void);       /* Report the FPU status word */
165 #define         _clear87        _clearfp
166 #define         _status87       _statusfp
167
168
169 /*
170    MSVCRT.dll _fpreset initializes the control register to 0x27f,
171    the status register to zero and the tag word to 0FFFFh.
172    This differs from asm instruction finit/fninit which set control
173    word to 0x37f (64 bit mantissa precison rather than 53 bit).
174    By default, the mingw version of _fpreset sets fp control as
175    per fninit. To use the MSVCRT.dll _fpreset, include CRT_fp8.o when
176    building your application.    
177 */
178 void _fpreset(void);        /* Reset the FPU */
179
180 /* Global 'variable' for the current floating point error code. */
181 int*  __fpecode(void);
182 #define _fpecode  (*(__fpecode()))
183
184 /*
185  * IEEE recommended functions.  MS puts them in float.h
186  * but they really belong in math.h.
187  */
188
189 double  _chgsign        (double);
190 double  _copysign       (double, double);
191 double  _logb           (double);
192 double  _nextafter      (double, double);
193 double  _scalb          (double, long);
194
195 int     _finite         (double);
196 int     _fpclass        (double);
197 int     _isnan          (double);
198
199 int     _isinf          (double); /* not exported */
200 int     _isnanl         (long double); /* not exported */
201 int     _isinfl         (long double); /* not exported */
202
203 #define isnan(x)        _isnan(x)
204 #define isinf(x)        _isinf(x)
205
206
207 #ifdef  __cplusplus
208 }
209 #endif
210
211 #endif  /* Not __STRICT_ANSI__ */
212
213 #endif /* _FLOAT_H_ */
214