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