|
|
|
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 |
|
#if _MSC_VER > 1000 |
17 |
|
#pragma once |
18 |
|
#endif |
19 |
|
|
20 |
|
#ifndef _INC_FLOAT |
21 |
|
#define _INC_FLOAT |
22 |
|
|
23 |
|
#include <crtdefs.h> |
24 |
|
#include <crtwrn.h> |
25 |
|
|
26 |
|
/* Define _CRT_MANAGED_FP_DEPRECATE */ |
27 |
|
#ifndef _CRT_MANAGED_FP_DEPRECATE |
28 |
|
#ifdef _CRT_MANAGED_FP_NO_DEPRECATE |
29 |
|
#define _CRT_MANAGED_FP_DEPRECATE |
30 |
|
#else |
31 |
|
#if defined(_M_CEE) |
32 |
|
#define _CRT_MANAGED_FP_DEPRECATE _CRT_DEPRECATE_TEXT("Direct floating point control is not supported or reliable from within managed code. ") |
33 |
|
#else |
34 |
|
#define _CRT_MANAGED_FP_DEPRECATE |
35 |
|
#endif |
36 |
|
#endif |
37 |
|
#endif |
38 |
|
|
39 |
|
#ifdef __cplusplus |
40 |
|
extern "C" { |
41 |
|
#endif |
42 |
|
|
43 |
|
#define DBL_DIG 15 /* # of decimal digits of precision */ |
44 |
|
#define DBL_EPSILON 2.2204460492503131e-016 /* smallest such that 1.0+DBL_EPSILON != 1.0 */ |
45 |
|
#define DBL_MANT_DIG 53 /* # of bits in mantissa */ |
46 |
|
#define DBL_MAX 1.7976931348623158e+308 /* max value */ |
47 |
|
#define DBL_MAX_10_EXP 308 /* max decimal exponent */ |
48 |
|
#define DBL_MAX_EXP 1024 /* max binary exponent */ |
49 |
|
#define DBL_MIN 2.2250738585072014e-308 /* min positive value */ |
50 |
|
#define DBL_MIN_10_EXP (-307) /* min decimal exponent */ |
51 |
|
#define DBL_MIN_EXP (-1021) /* min binary exponent */ |
52 |
|
#define _DBL_RADIX 2 /* exponent radix */ |
53 |
|
#define _DBL_ROUNDS 1 /* addition rounding: near */ |
54 |
|
|
55 |
|
#define FLT_DIG 6 /* # of decimal digits of precision */ |
56 |
|
#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */ |
57 |
|
#define FLT_GUARD 0 |
58 |
|
#define FLT_MANT_DIG 24 /* # of bits in mantissa */ |
59 |
|
#define FLT_MAX 3.402823466e+38F /* max value */ |
60 |
|
#define FLT_MAX_10_EXP 38 /* max decimal exponent */ |
61 |
|
#define FLT_MAX_EXP 128 /* max binary exponent */ |
62 |
|
#define FLT_MIN 1.175494351e-38F /* min positive value */ |
63 |
|
#define FLT_MIN_10_EXP (-37) /* min decimal exponent */ |
64 |
|
#define FLT_MIN_EXP (-125) /* min binary exponent */ |
65 |
|
#define FLT_NORMALIZE 0 |
66 |
|
#define FLT_RADIX 2 /* exponent radix */ |
67 |
|
#define FLT_ROUNDS 1 /* addition rounding: near */ |
68 |
|
|
69 |
|
#define LDBL_DIG DBL_DIG /* # of decimal digits of precision */ |
70 |
|
#define LDBL_EPSILON DBL_EPSILON /* smallest such that 1.0+LDBL_EPSILON != 1.0 */ |
71 |
|
#define LDBL_MANT_DIG DBL_MANT_DIG /* # of bits in mantissa */ |
72 |
|
#define LDBL_MAX DBL_MAX /* max value */ |
73 |
|
#define LDBL_MAX_10_EXP DBL_MAX_10_EXP /* max decimal exponent */ |
74 |
|
#define LDBL_MAX_EXP DBL_MAX_EXP /* max binary exponent */ |
75 |
|
#define LDBL_MIN DBL_MIN /* min positive value */ |
76 |
|
#define LDBL_MIN_10_EXP DBL_MIN_10_EXP /* min decimal exponent */ |
77 |
|
#define LDBL_MIN_EXP DBL_MIN_EXP /* min binary exponent */ |
78 |
|
#define _LDBL_RADIX DBL_RADIX /* exponent radix */ |
79 |
|
#define _LDBL_ROUNDS DBL_ROUNDS /* addition rounding: near */ |
80 |
|
|
81 |
|
/* Function prototypes */ |
82 |
|
|
83 |
|
/* Reading or writing the floating point control/status words is not supported in managed code */ |
84 |
|
|
85 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _clearfp(void); |
86 |
|
#pragma warning(push) |
87 |
|
#pragma warning(disable: 4141) |
88 |
|
_CRT_MANAGED_FP_DEPRECATE _CRT_INSECURE_DEPRECATE(_controlfp_s) _CRTIMP unsigned int __cdecl _controlfp(_In_ unsigned int _NewValue,_In_ unsigned int _Mask); |
89 |
|
#pragma warning(pop) |
90 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _set_controlfp(_In_ unsigned int _NewValue, _In_ unsigned int _Mask); |
91 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP errno_t __cdecl _controlfp_s(_Out_opt_ unsigned int *_CurrentState, _In_ unsigned int _NewValue, _In_ unsigned int _Mask); |
92 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _statusfp(void); |
93 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _fpreset(void); |
94 |
|
|
95 |
|
#if defined(_M_IX86) |
96 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl _statusfp2(_Out_opt_ unsigned int *_X86_status, _Out_opt_ unsigned int *_SSE2_status); |
97 |
|
#endif |
98 |
|
|
99 |
|
#define _clear87 _clearfp |
100 |
|
#define _status87 _statusfp |
101 |
|
|
102 |
|
/* |
103 |
|
* Abstract User Status Word bit definitions |
104 |
|
*/ |
105 |
|
|
106 |
|
#define _SW_INEXACT 0x00000001 /* inexact (precision) */ |
107 |
|
#define _SW_UNDERFLOW 0x00000002 /* underflow */ |
108 |
|
#define _SW_OVERFLOW 0x00000004 /* overflow */ |
109 |
|
#define _SW_ZERODIVIDE 0x00000008 /* zero divide */ |
110 |
|
#define _SW_INVALID 0x00000010 /* invalid */ |
111 |
|
#define _SW_DENORMAL 0x00080000 /* denormal status bit */ |
112 |
|
|
113 |
|
/* |
114 |
|
* New Control Bit that specifies the ambiguity in control word. |
115 |
|
*/ |
116 |
|
#define _EM_AMBIGUIOUS 0x80000000 /* for backwards compatibility old spelling */ |
117 |
|
#define _EM_AMBIGUOUS 0x80000000 |
118 |
|
|
119 |
|
/* |
120 |
|
* Abstract User Control Word Mask and bit definitions |
121 |
|
*/ |
122 |
|
#define _MCW_EM 0x0008001f /* interrupt Exception Masks */ |
123 |
|
#define _EM_INEXACT 0x00000001 /* inexact (precision) */ |
124 |
|
#define _EM_UNDERFLOW 0x00000002 /* underflow */ |
125 |
|
#define _EM_OVERFLOW 0x00000004 /* overflow */ |
126 |
|
#define _EM_ZERODIVIDE 0x00000008 /* zero divide */ |
127 |
|
#define _EM_INVALID 0x00000010 /* invalid */ |
128 |
|
#define _EM_DENORMAL 0x00080000 /* denormal exception mask (_control87 only) */ |
129 |
|
|
130 |
|
#define _MCW_RC 0x00000300 /* Rounding Control */ |
131 |
|
#define _RC_NEAR 0x00000000 /* near */ |
132 |
|
#define _RC_DOWN 0x00000100 /* down */ |
133 |
|
#define _RC_UP 0x00000200 /* up */ |
134 |
|
#define _RC_CHOP 0x00000300 /* chop */ |
135 |
|
|
136 |
|
/* |
137 |
|
* i386 specific definitions |
138 |
|
*/ |
139 |
|
#define _MCW_PC 0x00030000 /* Precision Control */ |
140 |
|
#define _PC_64 0x00000000 /* 64 bits */ |
141 |
|
#define _PC_53 0x00010000 /* 53 bits */ |
142 |
|
#define _PC_24 0x00020000 /* 24 bits */ |
143 |
|
|
144 |
|
#define _MCW_IC 0x00040000 /* Infinity Control */ |
145 |
|
#define _IC_AFFINE 0x00040000 /* affine */ |
146 |
|
#define _IC_PROJECTIVE 0x00000000 /* projective */ |
147 |
|
|
148 |
|
/* |
149 |
|
* RISC specific definitions |
150 |
|
*/ |
151 |
|
|
152 |
|
#define _MCW_DN 0x03000000 /* Denormal Control */ |
153 |
|
#define _DN_SAVE 0x00000000 /* save denormal results and operands */ |
154 |
|
#define _DN_FLUSH 0x01000000 /* flush denormal results and operands to zero */ |
155 |
|
#define _DN_FLUSH_OPERANDS_SAVE_RESULTS 0x02000000 /* flush operands to zero and save results */ |
156 |
|
#define _DN_SAVE_OPERANDS_FLUSH_RESULTS 0x03000000 /* save operands and flush results to zero */ |
157 |
|
|
158 |
|
/* initial Control Word value */ |
159 |
|
|
160 |
|
#if defined(_M_IX86) |
161 |
|
|
162 |
|
#define _CW_DEFAULT ( _RC_NEAR + _PC_53 + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL) |
163 |
|
|
164 |
|
#elif defined(_M_IA64) |
165 |
|
|
166 |
|
#define _CW_DEFAULT ( _RC_NEAR + _PC_64 + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL) |
167 |
|
|
168 |
|
#elif defined(_M_AMD64) |
169 |
|
|
170 |
|
#define _CW_DEFAULT ( _RC_NEAR + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL) |
171 |
|
|
172 |
|
#endif |
173 |
|
|
174 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP unsigned int __cdecl _control87(_In_ unsigned int _NewValue,_In_ unsigned int _Mask); |
175 |
|
#if defined(_M_IX86) |
176 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP int __cdecl __control87_2(_In_ unsigned int _NewValue, _In_ unsigned int _Mask, |
177 |
|
_Out_opt_ unsigned int* _X86_cw, _Out_opt_ unsigned int* _Sse2_cw); |
178 |
|
#endif |
179 |
|
|
180 |
|
/* Global variable holding floating point error code */ |
181 |
|
|
182 |
|
#if defined(_MT) || defined(_DLL) |
183 |
|
_Check_return_ _CRTIMP extern int * __cdecl __fpecode(void); |
184 |
|
#define _fpecode (*__fpecode()) |
185 |
|
#else /* ndef _MT && ndef _DLL */ |
186 |
|
extern int _fpecode; |
187 |
|
#endif /* _MT || _DLL */ |
188 |
|
|
189 |
|
/* invalid subconditions (_SW_INVALID also set) */ |
190 |
|
|
191 |
|
#define _SW_UNEMULATED 0x0040 /* unemulated instruction */ |
192 |
|
#define _SW_SQRTNEG 0x0080 /* square root of a neg number */ |
193 |
|
#define _SW_STACKOVERFLOW 0x0200 /* FP stack overflow */ |
194 |
|
#define _SW_STACKUNDERFLOW 0x0400 /* FP stack underflow */ |
195 |
|
|
196 |
|
/* Floating point error signals and return codes */ |
197 |
|
|
198 |
|
#define _FPE_INVALID 0x81 |
199 |
|
#define _FPE_DENORMAL 0x82 |
200 |
|
#define _FPE_ZERODIVIDE 0x83 |
201 |
|
#define _FPE_OVERFLOW 0x84 |
202 |
|
#define _FPE_UNDERFLOW 0x85 |
203 |
|
#define _FPE_INEXACT 0x86 |
204 |
|
|
205 |
|
#define _FPE_UNEMULATED 0x87 |
206 |
|
#define _FPE_SQRTNEG 0x88 |
207 |
|
#define _FPE_STACKOVERFLOW 0x8a |
208 |
|
#define _FPE_STACKUNDERFLOW 0x8b |
209 |
|
|
210 |
|
#define _FPE_EXPLICITGEN 0x8c /* raise( SIGFPE ); */ |
211 |
|
|
212 |
|
|
213 |
|
/* IEEE recommended functions */ |
214 |
|
|
215 |
|
#ifndef _SIGN_DEFINED |
216 |
|
_Check_return_ _CRTIMP double __cdecl _copysign (_In_ double _Number, _In_ double _Sign); |
217 |
|
_Check_return_ _CRTIMP double __cdecl _chgsign (_In_ double _X); |
218 |
|
#define _SIGN_DEFINED |
219 |
|
#endif |
220 |
|
_Check_return_ _CRTIMP double __cdecl _scalb(_In_ double _X, _In_ long _Y); |
221 |
|
_Check_return_ _CRTIMP double __cdecl _logb(_In_ double _X); |
222 |
|
_Check_return_ _CRTIMP double __cdecl _nextafter(_In_ double _X, _In_ double _Y); |
223 |
|
_Check_return_ _CRTIMP int __cdecl _finite(_In_ double _X); |
224 |
|
_Check_return_ _CRTIMP int __cdecl _isnan(_In_ double _X); |
225 |
|
_Check_return_ _CRTIMP int __cdecl _fpclass(_In_ double _X); |
226 |
|
|
227 |
|
#ifdef _M_AMD64 |
228 |
|
_Check_return_ _CRTIMP float __cdecl _scalbf(_In_ float _X, _In_ long _Y); |
229 |
|
#endif |
230 |
|
|
231 |
|
#define _FPCLASS_SNAN 0x0001 /* signaling NaN */ |
232 |
|
#define _FPCLASS_QNAN 0x0002 /* quiet NaN */ |
233 |
|
#define _FPCLASS_NINF 0x0004 /* negative infinity */ |
234 |
|
#define _FPCLASS_NN 0x0008 /* negative normal */ |
235 |
|
#define _FPCLASS_ND 0x0010 /* negative denormal */ |
236 |
|
#define _FPCLASS_NZ 0x0020 /* -0 */ |
237 |
|
#define _FPCLASS_PZ 0x0040 /* +0 */ |
238 |
|
#define _FPCLASS_PD 0x0080 /* positive denormal */ |
239 |
|
#define _FPCLASS_PN 0x0100 /* positive normal */ |
240 |
|
#define _FPCLASS_PINF 0x0200 /* positive infinity */ |
241 |
|
|
242 |
|
|
243 |
|
#if !__STDC__ |
244 |
|
|
245 |
|
/* Non-ANSI names for compatibility */ |
246 |
|
|
247 |
|
#define clear87 _clear87 |
248 |
|
#define status87 _status87 |
249 |
|
#define control87 _control87 |
250 |
|
|
251 |
|
_CRT_MANAGED_FP_DEPRECATE _CRTIMP void __cdecl fpreset(void); |
252 |
|
|
253 |
|
#define DBL_RADIX _DBL_RADIX |
254 |
|
#define DBL_ROUNDS _DBL_ROUNDS |
255 |
|
|
256 |
|
#define LDBL_RADIX _LDBL_RADIX |
257 |
|
#define LDBL_ROUNDS _LDBL_ROUNDS |
258 |
|
|
259 |
|
#define EM_AMBIGUIOUS _EM_AMBIGUOUS /* for backwards compatibility old spelling */ |
260 |
|
#define EM_AMBIGUOUS _EM_AMBIGUOUS |
261 |
|
|
262 |
|
#define MCW_EM _MCW_EM |
263 |
|
#define EM_INVALID _EM_INVALID |
264 |
|
#define EM_DENORMAL _EM_DENORMAL |
265 |
|
#define EM_ZERODIVIDE _EM_ZERODIVIDE |
266 |
|
#define EM_OVERFLOW _EM_OVERFLOW |
267 |
|
#define EM_UNDERFLOW _EM_UNDERFLOW |
268 |
|
#define EM_INEXACT _EM_INEXACT |
269 |
|
|
270 |
|
#define MCW_IC _MCW_IC |
271 |
|
#define IC_AFFINE _IC_AFFINE |
272 |
|
#define IC_PROJECTIVE _IC_PROJECTIVE |
273 |
|
|