:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[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  *  DISCLAMED. 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 #ifdef  __cplusplus
40 extern "C" {
41 #endif
42
43 #define FLT_ROUNDS      1
44 #define FLT_GUARD       1
45 #define FLT_NORMALIZE   1
46
47 /*
48  * The characteristics of float.
49  */
50
51 /* The radix for floating point representation. */
52 #define FLT_RADIX       2
53
54 /* Decimal digits of precision. */
55 #define FLT_DIG         6
56
57 /* Smallest number such that 1+x != 1 */
58 #define FLT_EPSILON     1.19209290e-07F
59
60 /* The number of base FLT_RADIX digits in the mantissa. */
61 #define FLT_MANT_DIG    24
62
63 /* The maximum floating point number. */
64 #define FLT_MAX         3.40282347e+38F
65
66 /* Maximum n such that FLT_RADIX^n - 1 is representable. */
67 #define FLT_MAX_EXP     128
68
69 /* Maximum n such that 10^n is representable. */
70 #define FLT_MAX_10_EXP  38
71
72 /* Minimum normalized floating-point number. */
73 #define FLT_MIN         1.17549435e-38F
74
75 /* Minimum n such that FLT_RADIX^n is a normalized number. */
76 #define FLT_MIN_EXP     (-125)
77
78 /* Minimum n such that 10^n is a normalized number. */
79 #define FLT_MIN_10_EXP  (-37)
80
81
82 /*
83  * The characteristics of double.
84  */
85 #define DBL_DIG         15
86 #define DBL_EPSILON     1.1102230246251568e-16
87 #define DBL_MANT_DIG    53
88 #define DBL_MAX         1.7976931348623157e+308
89 #define DBL_MAX_EXP     1024
90 #define DBL_MAX_10_EXP  308
91 #define DBL_MIN         2.2250738585072014e-308
92 #define DBL_MIN_EXP     (-1021)
93 #define DBL_MIN_10_EXP  (-307)
94
95
96 /*
97  * The characteristics of long double.
98  * NOTE: long double is the same as double.
99  */
100 #define LDBL_DIG        15
101 #define LDBL_EPSILON    1.1102230246251568e-16L
102 #define LDBL_MANT_DIG   53
103 #define LDBL_MAX        1.7976931348623157e+308L
104 #define LDBL_MAX_EXP    1024
105 #define LDBL_MAX_10_EXP 308
106 #define LDBL_MIN        2.2250738585072014e-308L
107 #define LDBL_MIN_EXP    (-1021)
108 #define LDBL_MIN_10_EXP (-307)
109
110
111 /*
112  * Functions and definitions for controlling the FPU.
113  */
114 #ifndef __STRICT_ANSI__
115
116 /* TODO: These constants are only valid for x86 machines */
117
118 /* Control word masks for unMask */
119 #define _MCW_EM         0x0008001F      /* Error masks */
120 #define _MCW_IC         0x00040000      /* Infinity */
121 #define _MCW_RC         0x00000300      /* Rounding */
122 #define _MCW_PC         0x00030000      /* Precision */
123
124 /* Control word values for unNew (use with related unMask above) */
125 #define _EM_INVALID     0x00000010
126 #define _EM_DENORMAL    0x00080000
127 #define _EM_ZERODIVIDE  0x00000008
128 #define _EM_OVERFLOW    0x00000004
129 #define _EM_UNDERFLOW   0x00000002
130 #define _EM_INEXACT     0x00000001
131 #define _IC_AFFINE      0x00040000
132 #define _IC_PROJECTIVE  0x00000000
133 #define _RC_CHOP        0x00000300
134 #define _RC_UP          0x00000200
135 #define _RC_DOWN        0x00000100
136 #define _RC_NEAR        0x00000000
137 #define _PC_24          0x00020000
138 #define _PC_53          0x00010000
139 #define _PC_64          0x00000000
140
141
142 /* Set the FPU control word as cw = (cw & ~unMask) | (unNew & unMask),
143  * i.e. change the bits in unMask to have the values they have in unNew,
144  * leaving other bits unchanged. */
145 unsigned int    _controlfp (unsigned int unNew, unsigned int unMask);
146 unsigned int    _control87 (unsigned int unNew, unsigned int unMask);
147
148
149 unsigned int    _clearfp (void);        /* Clear the FPU status word */
150 unsigned int    _statusfp (void);       /* Report the FPU status word */
151 #define         _clear87        _clearfp
152 #define         _status87       _statusfp
153
154 void            _fpreset (void);        /* Reset the FPU */
155
156 /* Global 'variable' for the current floating point error code. */
157 extern int *    __fpecode(void);
158 #define _fpecode        (*(__fpecode()))
159
160 /*
161  * IEEE recommended functions
162  */
163
164 double  _chgsign        (double x);
165 double  _copysign       (double dTo, double dFrom);
166 double  _logb           (double x);
167 double  _nextafter      (double x, double y);
168 double  _scalb          (double x, long n);
169
170 /* Return values for fpclass. */
171 #define _FPCLASS_SNAN   0x0001  /* Signaling "Not a Number" */
172 #define _FPCLASS_QNAN   0x0002  /* Quiet "Not a Number" */
173 #define _FPCLASS_NINF   0x0004  /* Negative Infinity */
174 #define _FPCLASS_NN     0x0008  /* Negative Normal */
175 #define _FPCLASS_ND     0x0010  /* Negative Denormal */
176 #define _FPCLASS_NZ     0x0020  /* Negative Zero */
177 #define _FPCLASS_PZ     0x0040  /* Positive Zero */
178 #define _FPCLASS_PD     0x0080  /* Positive Denormal */
179 #define _FPCLASS_PN     0x0100  /* Positive Normal */
180 #define _FPCLASS_PINF   0x0200  /* Positive Infinity */
181
182 int     _finite         (double x);
183 int     _fpclass        (double x);
184 int     _isnan          (double x);
185 int     _isinf          (double x); // not exported
186
187 int     _isnanl         (long double x); // not exported
188 int     _isinfl         (long double x); // not exported
189
190 #define isnan(x)        _isnan(x)
191 #define isinf(x)        _isinf(x)
192
193 #endif  /* Not __STRICT_ANSI__ */
194
195 #ifdef  __cplusplus
196 }
197 #endif
198
199 #endif /* _FLOAT_H_ */