home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / float.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  14KB  |  358 lines

  1. /***
  2. *float.h - constants for floating point values
  3. *
  4. *       Copyright (c) 1985-1997, 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  /* _MSC_VER > 1000 */
  19.  
  20. #ifndef _INC_FLOAT
  21. #define _INC_FLOAT
  22.  
  23. #if !defined (_WIN32) && !defined (_MAC)
  24. #error ERROR: Only Mac or Win32 targets supported!
  25. #endif  /* !defined (_WIN32) && !defined (_MAC) */
  26.  
  27. #ifndef _CRTBLD
  28. /* This version of the header files is NOT for user programs.
  29.  * It is intended for use when building the C runtimes ONLY.
  30.  * The version intended for public use will not have this message.
  31.  */
  32. #error ERROR: Use of C runtime library internal header file.
  33. #endif  /* _CRTBLD */
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif  /* __cplusplus */
  38.  
  39. #ifndef _INTERNAL_IFSTRIP_
  40. #include <cruntime.h>
  41. #endif  /* _INTERNAL_IFSTRIP_ */
  42.  
  43.  
  44. /* Define _CRTIMP */
  45.  
  46. #ifndef _CRTIMP
  47. #ifdef CRTDLL
  48. #define _CRTIMP __declspec(dllexport)
  49. #else  /* CRTDLL */
  50. #ifdef _DLL
  51. #define _CRTIMP __declspec(dllimport)
  52. #else  /* _DLL */
  53. #define _CRTIMP
  54. #endif  /* _DLL */
  55. #endif  /* CRTDLL */
  56. #endif  /* _CRTIMP */
  57.  
  58.  
  59. /* Define __cdecl for non-Microsoft compilers */
  60.  
  61. #if (!defined (_MSC_VER) && !defined (__cdecl))
  62. #define __cdecl
  63. #endif  /* (!defined (_MSC_VER) && !defined (__cdecl)) */
  64.  
  65. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  66.  
  67. #ifndef _CRTAPI1
  68. #if _MSC_VER >= 800 && _M_IX86 >= 300
  69. #define _CRTAPI1 __cdecl
  70. #else  /* _MSC_VER >= 800 && _M_IX86 >= 300 */
  71. #define _CRTAPI1
  72. #endif  /* _MSC_VER >= 800 && _M_IX86 >= 300 */
  73. #endif  /* _CRTAPI1 */
  74.  
  75. #define DBL_DIG         15                      /* # of decimal digits of precision */
  76. #define DBL_EPSILON     2.2204460492503131e-016 /* smallest such that 1.0+DBL_EPSILON != 1.0 */
  77. #define DBL_MANT_DIG    53                      /* # of bits in mantissa */
  78. #define DBL_MAX         1.7976931348623158e+308 /* max value */
  79. #define DBL_MAX_10_EXP  308                     /* max decimal exponent */
  80. #define DBL_MAX_EXP     1024                    /* max binary exponent */
  81. #define DBL_MIN         2.2250738585072014e-308 /* min positive value */
  82. #define DBL_MIN_10_EXP  (-307)                  /* min decimal exponent */
  83. #define DBL_MIN_EXP     (-1021)                 /* min binary exponent */
  84. #define _DBL_RADIX      2                       /* exponent radix */
  85. #define _DBL_ROUNDS     1                       /* addition rounding: near */
  86.  
  87. #define FLT_DIG         6                       /* # of decimal digits of precision */
  88. #define FLT_EPSILON     1.192092896e-07F        /* smallest such that 1.0+FLT_EPSILON != 1.0 */
  89. #define FLT_GUARD       0
  90. #define FLT_MANT_DIG    24                      /* # of bits in mantissa */
  91. #define FLT_MAX         3.402823466e+38F        /* max value */
  92. #define FLT_MAX_10_EXP  38                      /* max decimal exponent */
  93. #define FLT_MAX_EXP     128                     /* max binary exponent */
  94. #define FLT_MIN         1.175494351e-38F        /* min positive value */
  95. #define FLT_MIN_10_EXP  (-37)                   /* min decimal exponent */
  96. #define FLT_MIN_EXP     (-125)                  /* min binary exponent */
  97. #define FLT_NORMALIZE   0
  98. #define FLT_RADIX       2                       /* exponent radix */
  99. #define FLT_ROUNDS      1                       /* addition rounding: near */
  100.  
  101. #ifndef _M_M68K
  102. #define LDBL_DIG        DBL_DIG                 /* # of decimal digits of precision */
  103. #define LDBL_EPSILON    DBL_EPSILON             /* smallest such that 1.0+LDBL_EPSILON != 1.0 */
  104. #define LDBL_MANT_DIG   DBL_MANT_DIG            /* # of bits in mantissa */
  105. #define LDBL_MAX        DBL_MAX                 /* max value */
  106. #define LDBL_MAX_10_EXP DBL_MAX_10_EXP          /* max decimal exponent */
  107. #define LDBL_MAX_EXP    DBL_MAX_EXP             /* max binary exponent */
  108. #define LDBL_MIN        DBL_MIN                 /* min positive value */
  109. #define LDBL_MIN_10_EXP DBL_MIN_10_EXP          /* min decimal exponent */
  110. #define LDBL_MIN_EXP    DBL_MIN_EXP             /* min binary exponent */
  111. #define _LDBL_RADIX     DBL_RADIX               /* exponent radix */
  112. #define _LDBL_ROUNDS    DBL_ROUNDS              /* addition rounding: near */
  113. #else  /* _M_M68K */
  114. #define LDBL_DIG        18                                      /* # of decimal digits of precision */
  115. #define LDBL_EPSILON    1.08420217248550443412e-019L            /* smallest such that 1.0+LDBL_EPSILON != 1.0 */
  116. #define LDBL_MANT_DIG   64                                      /* # of bits in mantissa */
  117. #define LDBL_MAX        1.189731495357231765e+4932L             /* max value */
  118. #define LDBL_MAX_10_EXP 4932                                    /* max decimal exponent */
  119. #define LDBL_MAX_EXP    16384                                   /* max binary exponent */
  120. #define LDBL_MIN        3.3621031431120935063e-4932L            /* min positive value */
  121. #define LDBL_MIN_10_EXP (-4931)                                 /* min decimal exponent */
  122. #define LDBL_MIN_EXP    (-16381)                                /* min binary exponent */
  123. #define _LDBL_RADIX     2                                       /* exponent radix */
  124. #define _LDBL_ROUNDS    1                                       /* addition rounding: near */
  125. #endif  /* _M_M68K */
  126.  
  127. /* Function prototypes */
  128.  
  129. _CRTIMP unsigned int __cdecl _clearfp(void);
  130. _CRTIMP unsigned int __cdecl _controlfp(unsigned int,unsigned int);
  131. _CRTIMP unsigned int __cdecl _statusfp(void);
  132. _CRTIMP void __cdecl _fpreset(void);
  133.  
  134. #ifndef _MAC
  135. #define _clear87        _clearfp
  136. #define _status87       _statusfp
  137. #endif  /* _MAC */
  138.  
  139. /*
  140.  * Abstract User Control Word Mask and bit definitions
  141.  */
  142. #ifndef _MAC
  143. #define _MCW_EM         0x0008001f              /* interrupt Exception Masks */
  144. #else  /* _MAC */
  145. #define _MCW_EM         0x0000001f              /* interrupt Exception Masks */
  146. #endif  /* _MAC */
  147. #define _EM_INEXACT     0x00000001              /*   inexact (precision) */
  148. #define _EM_UNDERFLOW   0x00000002              /*   underflow */
  149. #define _EM_OVERFLOW    0x00000004              /*   overflow */
  150. #define _EM_ZERODIVIDE  0x00000008              /*   zero divide */
  151. #define _EM_INVALID     0x00000010              /*   invalid */
  152.  
  153. #define _MCW_RC         0x00000300              /* Rounding Control */
  154. #define _RC_NEAR        0x00000000              /*   near */
  155. #define _RC_DOWN        0x00000100              /*   down */
  156. #define _RC_UP          0x00000200              /*   up */
  157. #define _RC_CHOP        0x00000300              /*   chop */
  158.  
  159. /*
  160.  * Abstract User Status Word bit definitions
  161.  */
  162.  
  163. #define _SW_INEXACT     0x00000001              /* inexact (precision) */
  164. #define _SW_UNDERFLOW   0x00000002              /* underflow */
  165. #define _SW_OVERFLOW    0x00000004              /* overflow */
  166. #define _SW_ZERODIVIDE  0x00000008              /* zero divide */
  167. #define _SW_INVALID     0x00000010              /* invalid */
  168.  
  169.  
  170. /*
  171.  * i386 specific definitions
  172.  */
  173. #define _MCW_PC         0x00030000              /* Precision Control */
  174. #ifdef _M_MPPC
  175. /*
  176.  * PowerMac specific definitions(no precision control)
  177.  */
  178. #define _PC_64          0x00000000              /*    64 bits */
  179. #define _PC_53          0x00000000              /*    53 bits */
  180. #define _PC_24          0x00000000              /*    24 bits */
  181. #else  /* _M_MPPC */
  182. #define _PC_64          0x00000000              /*    64 bits */
  183. #define _PC_53          0x00010000              /*    53 bits */
  184. #define _PC_24          0x00020000              /*    24 bits */
  185. #endif  /* _M_MPPC */
  186.  
  187. #define _MCW_IC         0x00040000              /* Infinity Control */
  188. #define _IC_AFFINE      0x00040000              /*   affine */
  189. #define _IC_PROJECTIVE  0x00000000              /*   projective */
  190.  
  191. #define _EM_DENORMAL    0x00080000              /* denormal exception mask (_control87 only) */
  192.  
  193. #define _SW_DENORMAL    0x00080000              /* denormal status bit */
  194.  
  195.  
  196. _CRTIMP unsigned int __cdecl _control87(unsigned int,unsigned int);
  197.  
  198.  
  199. /*
  200.  * RISC specific definitions
  201.  */
  202.  
  203. #define _MCW_DN         0x03000000              /* Denormal Control */
  204. #define _DN_SAVE        0x00000000              /*   save denormal results and operands */
  205. #define _DN_FLUSH       0x01000000              /*   flush denormal results and operands to zero */
  206. #define _DN_FLUSH_OPERANDS_SAVE_RESULTS 0x02000000  /*   flush operands to zero and save results */
  207. #define _DN_SAVE_OPERANDS_FLUSH_RESULTS 0x03000000  /*   save operands and flush results to zero */
  208.  
  209.  
  210. /* initial Control Word value */
  211.  
  212. #if defined (_M_IX86)
  213.  
  214. #define _CW_DEFAULT ( _RC_NEAR + _PC_53 + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT + _EM_DENORMAL)
  215.  
  216. #elif defined (_MAC)
  217.  
  218. #define _CW_DEFAULT ( _RC_NEAR + _PC_64 + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT )
  219.  
  220. #elif defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
  221.  
  222. #define _CW_DEFAULT ( _RC_NEAR + _DN_FLUSH + _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW + _EM_INEXACT )
  223.  
  224. #endif  /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
  225.  
  226. /* Global variable holding floating point error code */
  227.  
  228. #if defined (_MT) || defined (_DLL)
  229. _CRTIMP extern int * __cdecl __fpecode(void);
  230. #define _fpecode        (*__fpecode())
  231. #else  /* defined (_MT) || defined (_DLL) */
  232. extern int _fpecode;
  233. #endif  /* defined (_MT) || defined (_DLL) */
  234.  
  235. /* invalid subconditions (_SW_INVALID also set) */
  236.  
  237. #define _SW_UNEMULATED          0x0040  /* unemulated instruction */
  238. #define _SW_SQRTNEG             0x0080  /* square root of a neg number */
  239. #define _SW_STACKOVERFLOW       0x0200  /* FP stack overflow */
  240. #define _SW_STACKUNDERFLOW      0x0400  /* FP stack underflow */
  241.  
  242. /*  Floating point error signals and return codes */
  243.  
  244. #define _FPE_INVALID            0x81
  245. #define _FPE_DENORMAL           0x82
  246. #define _FPE_ZERODIVIDE         0x83
  247. #define _FPE_OVERFLOW           0x84
  248. #define _FPE_UNDERFLOW          0x85
  249. #define _FPE_INEXACT            0x86
  250.  
  251. #define _FPE_UNEMULATED         0x87
  252. #define _FPE_SQRTNEG            0x88
  253. #define _FPE_STACKOVERFLOW      0x8a
  254. #define _FPE_STACKUNDERFLOW     0x8b
  255.  
  256. #define _FPE_EXPLICITGEN        0x8c    /* raise( SIGFPE ); */
  257.  
  258.  
  259. /* IEEE recommended functions */
  260.  
  261. _CRTIMP double __cdecl _copysign (double, double);
  262. _CRTIMP double __cdecl _chgsign (double);
  263. _CRTIMP double __cdecl _scalb(double, long);
  264. _CRTIMP double __cdecl _logb(double);
  265. _CRTIMP double __cdecl _nextafter(double, double);
  266. _CRTIMP int    __cdecl _finite(double);
  267. _CRTIMP int    __cdecl _isnan(double);
  268. _CRTIMP int    __cdecl _fpclass(double);
  269.  
  270. #define _FPCLASS_SNAN   0x0001  /* signaling NaN */
  271. #define _FPCLASS_QNAN   0x0002  /* quiet NaN */
  272. #define _FPCLASS_NINF   0x0004  /* negative infinity */
  273. #define _FPCLASS_NN     0x0008  /* negative normal */
  274. #define _FPCLASS_ND     0x0010  /* negative denormal */
  275. #define _FPCLASS_NZ     0x0020  /* -0 */
  276. #define _FPCLASS_PZ     0x0040  /* +0 */
  277. #define _FPCLASS_PD     0x0080  /* positive denormal */
  278. #define _FPCLASS_PN     0x0100  /* positive normal */
  279. #define _FPCLASS_PINF   0x0200  /* positive infinity */
  280.  
  281.  
  282. #if !__STDC__
  283.  
  284. /* Non-ANSI names for compatibility */
  285.  
  286. #ifndef _MAC
  287. #define clear87         _clear87
  288. #define status87        _status87
  289. #define control87       _control87
  290. #endif  /* _MAC */
  291.  
  292. _CRTIMP void __cdecl fpreset(void);
  293.  
  294. #define DBL_RADIX               _DBL_RADIX
  295. #define DBL_ROUNDS              _DBL_ROUNDS
  296.  
  297. #define LDBL_RADIX              _LDBL_RADIX
  298. #define LDBL_ROUNDS             _LDBL_ROUNDS
  299.  
  300. #define MCW_EM                  _MCW_EM
  301. #define EM_INVALID              _EM_INVALID
  302. #define EM_DENORMAL             _EM_DENORMAL
  303. #define EM_ZERODIVIDE           _EM_ZERODIVIDE
  304. #define EM_OVERFLOW             _EM_OVERFLOW
  305. #define EM_UNDERFLOW            _EM_UNDERFLOW
  306. #define EM_INEXACT              _EM_INEXACT
  307.  
  308. #define MCW_IC                  _MCW_IC
  309. #define IC_AFFINE               _IC_AFFINE
  310. #define IC_PROJECTIVE           _IC_PROJECTIVE
  311.  
  312. #define MCW_RC                  _MCW_RC
  313. #define RC_CHOP                 _RC_CHOP
  314. #define RC_UP                   _RC_UP
  315. #define RC_DOWN                 _RC_DOWN
  316. #define RC_NEAR                 _RC_NEAR
  317.  
  318. #define MCW_PC                  _MCW_PC
  319. #define PC_24                   _PC_24
  320. #define PC_53                   _PC_53
  321. #define PC_64                   _PC_64
  322.  
  323. #define CW_DEFAULT              _CW_DEFAULT
  324.  
  325. #define SW_INVALID              _SW_INVALID
  326. #define SW_DENORMAL             _SW_DENORMAL
  327. #define SW_ZERODIVIDE           _SW_ZERODIVIDE
  328. #define SW_OVERFLOW             _SW_OVERFLOW
  329. #define SW_UNDERFLOW            _SW_UNDERFLOW
  330. #define SW_INEXACT              _SW_INEXACT
  331.  
  332. #define SW_UNEMULATED           _SW_UNEMULATED
  333. #define SW_SQRTNEG              _SW_SQRTNEG
  334. #define SW_STACKOVERFLOW        _SW_STACKOVERFLOW
  335. #define SW_STACKUNDERFLOW       _SW_STACKUNDERFLOW
  336.  
  337. #define FPE_INVALID             _FPE_INVALID
  338. #define FPE_DENORMAL            _FPE_DENORMAL
  339. #define FPE_ZERODIVIDE          _FPE_ZERODIVIDE
  340. #define FPE_OVERFLOW            _FPE_OVERFLOW
  341. #define FPE_UNDERFLOW           _FPE_UNDERFLOW
  342. #define FPE_INEXACT             _FPE_INEXACT
  343.  
  344. #define FPE_UNEMULATED          _FPE_UNEMULATED
  345. #define FPE_SQRTNEG             _FPE_SQRTNEG
  346. #define FPE_STACKOVERFLOW       _FPE_STACKOVERFLOW
  347. #define FPE_STACKUNDERFLOW      _FPE_STACKUNDERFLOW
  348.  
  349. #define FPE_EXPLICITGEN         _FPE_EXPLICITGEN
  350.  
  351. #endif  /* !__STDC__ */
  352.  
  353. #ifdef __cplusplus
  354. }
  355. #endif  /* __cplusplus */
  356.  
  357. #endif  /* _INC_FLOAT */
  358.