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