STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
float.h
Go to the documentation of this file.
1 /***
2 *float.h - constants for floating point values
3 *
4 * Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 * This file contains defines for a number of implementation dependent
8 * values which are commonly used by sophisticated numerical (floating
9 * point) programs.
10 * [ANSI]
11 *
12 * [Public]
13 *
14 ****/
15 
16 #pragma once
17 
18 #ifndef _INC_FLOAT
19 #define _INC_FLOAT
20 
21 #include <crtdefs.h>
22 #include <crtwrn.h>
23 
24 /* Define _CRT_MANAGED_FP_DEPRECATE */
25 #ifndef _CRT_MANAGED_FP_DEPRECATE
26 #ifdef _CRT_MANAGED_FP_NO_DEPRECATE
27 #define _CRT_MANAGED_FP_DEPRECATE
28 #else /* _CRT_MANAGED_FP_NO_DEPRECATE */
29 #if defined (_M_CEE)
30 #define _CRT_MANAGED_FP_DEPRECATE _CRT_DEPRECATE_TEXT("Direct floating point control is not supported or reliable from within managed code. ")
31 #else /* defined (_M_CEE) */
32 #define _CRT_MANAGED_FP_DEPRECATE
33 #endif /* defined (_M_CEE) */
34 #endif /* _CRT_MANAGED_FP_NO_DEPRECATE */
35 #endif /* _CRT_MANAGED_FP_DEPRECATE */
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40 
41 /*
42 Define the floating point precision used.
43 
44 For x86, results are in double precision (unless /arch:sse2
45  is used, in which case results are in source precision).
46 
47 For x64 and ARM, results are in source precision.
48 
49 If the compiler is invoked with /fp:fast, the compiler is
50  allowed to use the fastest precision and even mix within
51  a single function, so precision is indeterminable.
52 
53 Note that manipulating the floating point behavior using the
54  float_control/fenv_access/fp_contract #pragmas may alter the
55  actual floating point evaluation method, which may in turn
56  invalidate the value of FLT_EVAL_METHOD.
57 */
58 
59 #if defined(_M_FP_FAST)
60 #define FLT_EVAL_METHOD -1
61 #else
62 #if defined(_M_IX86)
63 #if _M_IX86_FP == 2
64 #define FLT_EVAL_METHOD 0
65 #else
66 #define FLT_EVAL_METHOD 2
67 #endif
68 #else
69 #define FLT_EVAL_METHOD 0
70 #endif
71 #endif
72 
73 #define DBL_DIG 15 /* # of decimal digits of precision */
74 #define DBL_EPSILON 2.2204460492503131e-016 /* smallest such that 1.0+DBL_EPSILON != 1.0 */
75 #define DBL_MANT_DIG 53 /* # of bits in mantissa */
76 #define DBL_MAX 1.7976931348623158e+308 /* max value */
77 #define DBL_MAX_10_EXP 308 /* max decimal exponent */
78 #define DBL_MAX_EXP 1024 /* max binary exponent */
79 #define DBL_MIN 2.2250738585072014e-308 /* min positive value */
80 #define DBL_MIN_10_EXP (-307) /* min decimal exponent */
81 #define DBL_MIN_EXP (-1021) /* min binary exponent */
82 #define _DBL_RADIX 2 /* exponent radix */
83 #define _DBL_ROUNDS 1 /* addition rounding: near */
84 
85 #define FLT_DIG 6 /* # of decimal digits of precision */
86 #define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */
87 #define FLT_GUARD 0
88 #define FLT_MANT_DIG 24 /* # of bits in mantissa */
89 #define FLT_MAX 3.402823466e+38F /* max value */
90 #define FLT_MAX_10_EXP 38 /* max decimal exponent */
91 #define FLT_MAX_EXP 128 /* max binary exponent */
92 #define FLT_MIN 1.175494351e-38F /* min positive value */
93 #define FLT_MIN_10_EXP (-37) /* min decimal exponent */
94 #define FLT_MIN_EXP (-125) /* min binary exponent */
95 #define FLT_NORMALIZE 0
96 #define FLT_RADIX 2 /* exponent radix */
97 #define FLT_ROUNDS 1 /* addition rounding: near */
98 
99 #define LDBL_DIG DBL_DIG /* # of decimal digits of precision */
100 #define LDBL_EPSILON DBL_EPSILON /* smallest such that 1.0+LDBL_EPSILON != 1.0 */
101 #define LDBL_MANT_DIG DBL_MANT_DIG /* # of bits in mantissa */
102 #define LDBL_MAX DBL_MAX /* max value */
103 #define LDBL_MAX_10_EXP DBL_MAX_10_EXP /* max decimal exponent */
104 #define LDBL_MAX_EXP DBL_MAX_EXP /* max binary exponent */
105 #define LDBL_MIN DBL_MIN /* min positive value */
106 #define LDBL_MIN_10_EXP DBL_MIN_10_EXP /* min decimal exponent */
107 #define LDBL_MIN_EXP DBL_MIN_EXP /* min binary exponent */
108 #define _LDBL_RADIX DBL_RADIX /* exponent radix */
109 #define _LDBL_ROUNDS DBL_ROUNDS /* addition rounding: near */
110 
111 #define DECIMAL_DIG 10 /* float rounded to decimal and back */
112 
113 /* Function prototypes */
114 
115 /* Reading or writing the floating point control/status words is not supported in managed code */
116 
117 _CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _clearfp(void);
118 #pragma warning(push)
119 #pragma warning(disable: 4141)
120 _CRT_MANAGED_FP_DEPRECATE _CRT_INSECURE_DEPRECATE(_controlfp_s) _CRTIMP unsigned int __cdecl _controlfp(_In_ unsigned int _NewValue,_In_ unsigned int _Mask);
121 #pragma warning(pop)
122 _CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _set_controlfp(_In_ unsigned int _NewValue, _In_ unsigned int _Mask);
123 _CRT_MANAGED_FP_DEPRECATE _CRTIMP errno_t __cdecl _controlfp_s(_Out_opt_ unsigned int *_CurrentState, _In_ unsigned int _NewValue, _In_ unsigned int _Mask);
124 _CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _statusfp(void);
125 _CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _fpreset(void);
126 
127 #if defined (_M_IX86)
128 _CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _statusfp2(_Out_opt_ unsigned int *_X86_status, _Out_opt_ unsigned int *_SSE2_status);
129 #endif /* defined (_M_IX86) */
130 
131 #define _clear87 _clearfp
132 #define _status87 _statusfp
133 
134 /*
135  * Abstract User Status Word bit definitions
136  */
137 
138 #define _SW_INEXACT 0x00000001 /* inexact (precision) */
139 #define _SW_UNDERFLOW 0x00000002 /* underflow */
140 #define _SW_OVERFLOW 0x00000004 /* overflow */
141 #define _SW_ZERODIVIDE 0x00000008 /* zero divide */
142 #define _SW_INVALID 0x00000010 /* invalid */
143 #define _SW_DENORMAL 0x00080000 /* denormal status bit */
144 
145 /*
146  * New Control Bit that specifies the ambiguity in control word.
147  */
148 #define _EM_AMBIGUIOUS 0x80000000 /* for backwards compatibility old spelling */
149 #define _EM_AMBIGUOUS 0x80000000
150 
151 /*
152  * Abstract User Control Word Mask and bit definitions
153  */
154 #define _MCW_EM 0x0008001f /* interrupt Exception Masks */
155 #define _EM_INEXACT 0x00000001 /* inexact (precision) */
156 #define _EM_UNDERFLOW 0x00000002 /* underflow */
157 #define _EM_OVERFLOW 0x00000004 /* overflow */
158 #define _EM_ZERODIVIDE 0x00000008 /* zero divide */
159 #define _EM_INVALID 0x00000010 /* invalid */
160 #define _EM_DENORMAL 0x00080000 /* denormal exception mask (_control87 only) */
161 
162 #define _MCW_RC 0x00000300 /* Rounding Control */
163 #define _RC_NEAR 0x00000000 /* near */
164 #define _RC_DOWN 0x00000100 /* down */
165 #define _RC_UP 0x00000200 /* up */
166 #define _RC_CHOP 0x00000300 /* chop */
167 
168 /*
169  * i386 specific definitions
170  */
171 #define _MCW_PC 0x00030000 /* Precision Control */
172 #define _PC_64 0x00000000 /* 64 bits */
173 #define _PC_53 0x00010000 /* 53 bits */
174 #define _PC_24 0x00020000 /* 24 bits */
175 
176 #define _MCW_IC 0x00040000 /* Infinity Control */
177 #define _IC_AFFINE 0x00040000 /* affine */
178 #define _IC_PROJECTIVE 0x00000000 /* projective */
179 
180 /*
181  * RISC specific definitions
182  */
183 
184 #define _MCW_DN 0x03000000 /* Denormal Control */
185 #define _DN_SAVE 0x00000000 /* save denormal results and operands */
186 #define _DN_FLUSH 0x01000000 /* flush denormal results and operands to zero */
187 #define _DN_FLUSH_OPERANDS_SAVE_RESULTS 0x02000000 /* flush operands to zero and save results */
188 #define _DN_SAVE_OPERANDS_FLUSH_RESULTS 0x03000000 /* save operands and flush results to zero */
189 
190 /* initial Control Word value */
191 
192 #if defined (_M_IX86)
193 
194 #define _CW_DEFAULT ( _RC_NEAR + _PC_53 + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL)
195 
196 #elif defined (_M_X64) || defined (_M_ARM)
197 
198 #define _CW_DEFAULT ( _RC_NEAR + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL)
199 
200 #endif /* defined (_M_X64) || defined (_M_ARM) */
201 
202 _CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _control87(_In_ unsigned int _NewValue,_In_ unsigned int _Mask);
203 #if defined (_M_IX86)
204 _CRT_MANAGED_FP_DEPRECATE _CRTIMP int __cdecl __control87_2(_In_ unsigned int _NewValue, _In_ unsigned int _Mask,
205  _Out_opt_ unsigned int* _X86_cw, _Out_opt_ unsigned int* _Sse2_cw);
206 #endif /* defined (_M_IX86) */
207 
208 /* Global variable holding floating point error code */
209 
210 _Check_return_ _CRTIMP extern int * __cdecl __fpecode(void);
211 #define _fpecode (*__fpecode())
212 
213 /* invalid subconditions (_SW_INVALID also set) */
214 
215 #define _SW_UNEMULATED 0x0040 /* unemulated instruction */
216 #define _SW_SQRTNEG 0x0080 /* square root of a neg number */
217 #define _SW_STACKOVERFLOW 0x0200 /* FP stack overflow */
218 #define _SW_STACKUNDERFLOW 0x0400 /* FP stack underflow */
219 
220 /* Floating point error signals and return codes */
221 
222 #define _FPE_INVALID 0x81
223 #define _FPE_DENORMAL 0x82
224 #define _FPE_ZERODIVIDE 0x83
225 #define _FPE_OVERFLOW 0x84
226 #define _FPE_UNDERFLOW 0x85
227 #define _FPE_INEXACT 0x86
228 
229 #define _FPE_UNEMULATED 0x87
230 #define _FPE_SQRTNEG 0x88
231 #define _FPE_STACKOVERFLOW 0x8a
232 #define _FPE_STACKUNDERFLOW 0x8b
233 
234 #define _FPE_EXPLICITGEN 0x8c /* raise( SIGFPE ); */
235 
236 #define _FPE_MULTIPLE_TRAPS 0x8d /* on x86 with arch:SSE2 OS returns these exceptions */
237 #define _FPE_MULTIPLE_FAULTS 0x8e
238 
239 /* IEEE recommended functions */
240 
241 _Check_return_ _CRTIMP double __cdecl _copysign(_In_ double _Number, _In_ double _Sign);
242 _Check_return_ _CRTIMP double __cdecl _chgsign(_In_ double _X);
243 _Check_return_ _CRTIMP double __cdecl _scalb(_In_ double _X, _In_ long _Y);
244 _Check_return_ _CRTIMP double __cdecl _logb(_In_ double _X);
245 _Check_return_ _CRTIMP double __cdecl _nextafter(_In_ double _X, _In_ double _Y);
246 _Check_return_ _CRTIMP int __cdecl _finite(_In_ double _X);
247 _Check_return_ _CRTIMP int __cdecl _isnan(_In_ double _X);
248 _Check_return_ _CRTIMP int __cdecl _fpclass(_In_ double _X);
249 
250 #ifdef _M_X64
251 _Check_return_ _CRTIMP float __cdecl _scalbf(_In_ float _X, _In_ long _Y);
252 #endif /* _M_X64 */
253 
254 #define _FPCLASS_SNAN 0x0001 /* signaling NaN */
255 #define _FPCLASS_QNAN 0x0002 /* quiet NaN */
256 #define _FPCLASS_NINF 0x0004 /* negative infinity */
257 #define _FPCLASS_NN 0x0008 /* negative normal */
258 #define _FPCLASS_ND 0x0010 /* negative denormal */
259 #define _FPCLASS_NZ 0x0020 /* -0 */
260 #define _FPCLASS_PZ 0x0040 /* +0 */
261 #define _FPCLASS_PD 0x0080 /* positive denormal */
262 #define _FPCLASS_PN 0x0100 /* positive normal */
263 #define _FPCLASS_PINF 0x0200 /* positive infinity */
264 
265 
266 #if !__STDC__
267 
268 /* Non-ANSI names for compatibility */
269 
270 #define clear87 _clear87
271 #define status87 _status87
272 #define control87 _control87
273 
274 _CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl fpreset(void);
275 
276 #define DBL_RADIX _DBL_RADIX
277 #define DBL_ROUNDS _DBL_ROUNDS
278 
279 #define LDBL_RADIX _LDBL_RADIX
280 #define LDBL_ROUNDS _LDBL_ROUNDS
281 
282 #define EM_AMBIGUIOUS _EM_AMBIGUOUS /* for backwards compatibility old spelling */
283 #define EM_AMBIGUOUS _EM_AMBIGUOUS
284 
285 #define MCW_EM _MCW_EM
286 #define EM_INVALID _EM_INVALID
287 #define EM_DENORMAL _EM_DENORMAL
288 #define EM_ZERODIVIDE _EM_ZERODIVIDE
289 #define EM_OVERFLOW _EM_OVERFLOW
290 #define EM_UNDERFLOW _EM_UNDERFLOW
291 #define EM_INEXACT _EM_INEXACT
292 
293 #define MCW_IC _MCW_IC
294 #define IC_AFFINE _IC_AFFINE
295 #define IC_PROJECTIVE _IC_PROJECTIVE
296 
297 #define MCW_RC _MCW_RC
298 #define RC_CHOP _RC_CHOP
299 #define RC_UP _RC_UP
300 #define RC_DOWN _RC_DOWN
301 #define RC_NEAR _RC_NEAR
302 
303 #define MCW_PC _MCW_PC
304 #define PC_24 _PC_24
305 #define PC_53 _PC_53
306 #define PC_64 _PC_64
307 
308 #define CW_DEFAULT _CW_DEFAULT
309 
310 #define SW_INVALID _SW_INVALID
311 #define SW_DENORMAL _SW_DENORMAL
312 #define SW_ZERODIVIDE _SW_ZERODIVIDE
313 #define SW_OVERFLOW _SW_OVERFLOW
314 #define SW_UNDERFLOW _SW_UNDERFLOW
315 #define SW_INEXACT _SW_INEXACT
316 
317 #define SW_UNEMULATED _SW_UNEMULATED
318 #define SW_SQRTNEG _SW_SQRTNEG
319 #define SW_STACKOVERFLOW _SW_STACKOVERFLOW
320 #define SW_STACKUNDERFLOW _SW_STACKUNDERFLOW
321 
322 #define FPE_INVALID _FPE_INVALID
323 #define FPE_DENORMAL _FPE_DENORMAL
324 #define FPE_ZERODIVIDE _FPE_ZERODIVIDE
325 #define FPE_OVERFLOW _FPE_OVERFLOW
326 #define FPE_UNDERFLOW _FPE_UNDERFLOW
327 #define FPE_INEXACT _FPE_INEXACT
328 
329 #define FPE_UNEMULATED _FPE_UNEMULATED
330 #define FPE_SQRTNEG _FPE_SQRTNEG
331 #define FPE_STACKOVERFLOW _FPE_STACKOVERFLOW
332 #define FPE_STACKUNDERFLOW _FPE_STACKUNDERFLOW
333 
334 #define FPE_EXPLICITGEN _FPE_EXPLICITGEN
335 
336 #endif /* !__STDC__ */
337 
338 #ifdef __cplusplus
339 }
340 #endif /* __cplusplus */
341 
342 #endif /* _INC_FLOAT */
_CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _statusfp(void)
#define _Out_opt_
Definition: sal.h:352
#define _CRTIMP
Definition: crtdefs.h:23
_Check_return_ _CRTIMP int __cdecl _isnan(_In_ double _X)
_Check_return_ _CRTIMP int *__cdecl __fpecode(void)
_Check_return_ _CRTIMP int __cdecl _finite(_In_ double _X)
_Check_return_ _CRTIMP double __cdecl _logb(_In_ double _X)
_Check_return_ _CRTIMP double __cdecl _scalb(_In_ double _X, _In_ long _Y)
_CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _set_controlfp(_In_ unsigned int _NewValue, _In_ unsigned int _Mask)
_CRT_MANAGED_FP_DEPRECATE _CRT_INSECURE_DEPRECATE(_controlfp_s) _CRTIMP unsigned int __cdecl _controlfp(_In_ unsigned int _NewValue
#define _Check_return_
Definition: sal.h:563
_Check_return_ _CRTIMP double __cdecl _chgsign(_In_ double _X)
#define _In_
Definition: sal.h:314
_In_ double _Y
Definition: math.h:999
_CRT_MANAGED_FP_DEPRECATE _CRTIMP errno_t __cdecl _controlfp_s(_Out_opt_ unsigned int *_CurrentState, _In_ unsigned int _NewValue, _In_ unsigned int _Mask)
_Check_return_ _CRTIMP int __cdecl _fpclass(_In_ double _X)
_Check_return_ _CRTIMP double __cdecl _nextafter(_In_ double _X, _In_ double _Y)
_CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _fpreset(void)
_CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl fpreset(void)
int errno_t
Definition: crtdefs.h:563
#define _CRT_MANAGED_FP_DEPRECATE
Definition: float.h:32
_CRT_MANAGED_FP_DEPRECATE _In_ unsigned int _Mask
Definition: float.h:120
_CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _control87(_In_ unsigned int _NewValue, _In_ unsigned int _Mask)
_Check_return_ _CRTIMP double __cdecl _copysign(_In_ double _Number, _In_ double _Sign)
_CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _clearfp(void)