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

  1. /***
  2. *fpieee.h - Definitions for floating point IEEE exception handling
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       This file contains constant and type definitions for handling
  8. *       floating point exceptions [ANSI/IEEE std. 754]
  9. *
  10. *       [Public]
  11. *
  12. ****/
  13.  
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif  /* _MSC_VER > 1000 */
  17.  
  18. #ifndef _INC_FPIEEE
  19. #define _INC_FPIEEE
  20.  
  21. #if !defined (_WIN32) && !defined (_MAC)
  22. #error ERROR: Only Mac or Win32 targets supported!
  23. #endif  /* !defined (_WIN32) && !defined (_MAC) */
  24.  
  25. #ifndef _CRTBLD
  26. /* This version of the header files is NOT for user programs.
  27.  * It is intended for use when building the C runtimes ONLY.
  28.  * The version intended for public use will not have this message.
  29.  */
  30. #error ERROR: Use of C runtime library internal header file.
  31. #endif  /* _CRTBLD */
  32.  
  33. #ifndef __assembler
  34.  
  35. #ifdef _MSC_VER
  36. /*
  37.  * Currently, all MS C compilers for Win32 platforms default to 8 byte
  38.  * alignment.
  39.  */
  40. #pragma pack(push,8)
  41. #endif  /* _MSC_VER */
  42.  
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif  /* __cplusplus */
  46.  
  47. #ifndef _INTERNAL_IFSTRIP_
  48. #include <cruntime.h>
  49. #endif  /* _INTERNAL_IFSTRIP_ */
  50.  
  51.  
  52. /* Define _CRTIMP */
  53.  
  54. #ifndef _CRTIMP
  55. #ifdef CRTDLL
  56. #define _CRTIMP __declspec(dllexport)
  57. #else  /* CRTDLL */
  58. #ifdef _DLL
  59. #define _CRTIMP __declspec(dllimport)
  60. #else  /* _DLL */
  61. #define _CRTIMP
  62. #endif  /* _DLL */
  63. #endif  /* CRTDLL */
  64. #endif  /* _CRTIMP */
  65.  
  66.  
  67. /* Define __cdecl for non-Microsoft compilers */
  68.  
  69. #if (!defined (_MSC_VER) && !defined (__cdecl))
  70. #define __cdecl
  71. #endif  /* (!defined (_MSC_VER) && !defined (__cdecl)) */
  72.  
  73. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  74.  
  75. #ifndef _CRTAPI1
  76. #if _MSC_VER >= 800 && _M_IX86 >= 300
  77. #define _CRTAPI1 __cdecl
  78. #else  /* _MSC_VER >= 800 && _M_IX86 >= 300 */
  79. #define _CRTAPI1
  80. #endif  /* _MSC_VER >= 800 && _M_IX86 >= 300 */
  81. #endif  /* _CRTAPI1 */
  82.  
  83. /*
  84.  * Define floating point IEEE compare result values.
  85.  */
  86.  
  87. typedef enum {
  88.     _FpCompareEqual,
  89.     _FpCompareGreater,
  90.     _FpCompareLess,
  91.     _FpCompareUnordered
  92. } _FPIEEE_COMPARE_RESULT;
  93.  
  94. /*
  95.  * Define floating point format and result precision values.
  96.  */
  97.  
  98. typedef enum {
  99.     _FpFormatFp32,
  100.     _FpFormatFp64,
  101.     _FpFormatFp80,
  102.     _FpFormatFp128,
  103.     _FpFormatI16,
  104.     _FpFormatI32,
  105.     _FpFormatI64,
  106.     _FpFormatU16,
  107.     _FpFormatU32,
  108.     _FpFormatU64,
  109.     _FpFormatBcd80,
  110.     _FpFormatCompare,
  111.     _FpFormatString
  112. } _FPIEEE_FORMAT;
  113.  
  114. /*
  115.  * Define operation code values.
  116.  */
  117.  
  118. typedef enum {
  119.     _FpCodeUnspecified,
  120.     _FpCodeAdd,
  121.     _FpCodeSubtract,
  122.     _FpCodeMultiply,
  123.     _FpCodeDivide,
  124.     _FpCodeSquareRoot,
  125.     _FpCodeRemainder,
  126.     _FpCodeCompare,
  127.     _FpCodeConvert,
  128.     _FpCodeRound,
  129.     _FpCodeTruncate,
  130.     _FpCodeFloor,
  131.     _FpCodeCeil,
  132.     _FpCodeAcos,
  133.     _FpCodeAsin,
  134.     _FpCodeAtan,
  135.     _FpCodeAtan2,
  136.     _FpCodeCabs,
  137.     _FpCodeCos,
  138.     _FpCodeCosh,
  139.     _FpCodeExp,
  140.     _FpCodeFabs,
  141.     _FpCodeFmod,
  142.     _FpCodeFrexp,
  143.     _FpCodeHypot,
  144.     _FpCodeLdexp,
  145.     _FpCodeLog,
  146.     _FpCodeLog10,
  147.     _FpCodeModf,
  148.     _FpCodePow,
  149.     _FpCodeSin,
  150.     _FpCodeSinh,
  151.     _FpCodeTan,
  152.     _FpCodeTanh,
  153.     _FpCodeY0,
  154.     _FpCodeY1,
  155.     _FpCodeYn,
  156.     _FpCodeLogb,
  157.     _FpCodeNextafter,
  158.     _FpCodeNegate
  159.  
  160. } _FP_OPERATION_CODE;
  161.  
  162. #endif  /* __assembler */
  163. #ifndef _INTERNAL_IFSTRIP_
  164. #ifndef __assembler
  165.  
  166. #define OP_UNSPEC    _FpCodeUnspecified
  167. #define OP_ADD       _FpCodeAdd
  168. #define OP_SUB       _FpCodeSubtract
  169. #define OP_MUL       _FpCodeMultiply
  170. #define OP_DIV       _FpCodeDivide
  171. #define OP_REM       _FpCodeRemainder
  172. #define OP_COMP      _FpCodeCompare
  173. #define OP_CVT       _FpCodeConvert
  174. #define OP_RND       _FpCodeRound
  175. #define OP_TRUNC     _FpCodeTruncate
  176.  
  177. #define OP_EXP       _FpCodeExp
  178.  
  179. #define OP_POW       _FpCodePow
  180. #define OP_LOG       _FpCodeLog
  181. #define OP_LOG10     _FpCodeLog10
  182. #define OP_SINH      _FpCodeSinh
  183. #define OP_COSH      _FpCodeCosh
  184. #define OP_TANH      _FpCodeTanh
  185. #define OP_ASIN      _FpCodeAsin
  186. #define OP_ACOS      _FpCodeAcos
  187. #define OP_ATAN      _FpCodeAtan
  188. #define OP_ATAN2     _FpCodeAtan2
  189. #define OP_SQRT      _FpCodeSquareRoot
  190. #define OP_SIN       _FpCodeSin
  191. #define OP_COS       _FpCodeCos
  192. #define OP_TAN       _FpCodeTan
  193. #define OP_CEIL      _FpCodeCeil
  194. #define OP_FLOOR     _FpCodeFloor
  195. #define OP_ABS       _FpCodeFabs
  196. #define OP_MODF      _FpCodeModf
  197. #define OP_LDEXP     _FpCodeLdexp
  198. #define OP_CABS      _FpCodeCabs
  199. #define OP_HYPOT     _FpCodeHypot
  200. #define OP_FMOD      _FpCodeFmod
  201. #define OP_FREXP     _FpCodeFrexp
  202. #define OP_Y0        _FpCodeY0
  203. #define OP_Y1        _FpCodeY1
  204. #define OP_YN        _FpCodeYn
  205.  
  206. #define OP_LOGB       _FpCodeLogb
  207. #define OP_NEXTAFTER  _FpCodeNextafter
  208. #else  /* __assembler */
  209.  
  210. /* This must be the same as the enumerator _FP_OPERATION_CODE ! */
  211. #define OP_UNSPEC    0
  212. #define OP_ADD       1
  213. #define OP_SUB       2
  214. #define OP_MUL       3
  215. #define OP_DIV       4
  216. #define OP_SQRT      5
  217. #define OP_REM       6
  218. #define OP_COMP      7
  219. #define OP_CVT       8
  220. #define OP_RND       9
  221. #define OP_TRUNC     10
  222. #define OP_FLOOR     11
  223. #define OP_CEIL      12
  224. #define OP_ACOS      13
  225. #define OP_ASIN      14
  226. #define OP_ATAN      15
  227. #define OP_ATAN2     16
  228. #define OP_CABS      17
  229. #define OP_COS       18
  230. #define OP_COSH      19
  231. #define OP_EXP       20
  232. #define OP_ABS       21         /* same as OP_FABS */
  233. #define OP_FABS      21         /* same as OP_ABS  */
  234. #define OP_FMOD      22
  235. #define OP_FREXP     23
  236. #define OP_HYPOT     24
  237. #define OP_LDEXP     25
  238. #define OP_LOG       26
  239. #define OP_LOG10     27
  240. #define OP_MODF      28
  241. #define OP_POW       29
  242. #define OP_SIN       30
  243. #define OP_SINH      31
  244. #define OP_TAN       32
  245. #define OP_TANH      33
  246. #define OP_Y0        34
  247. #define OP_Y1        35
  248. #define OP_YN        36
  249. #define OP_LOGB       37
  250. #define OP_NEXTAFTER  38
  251. #define OP_NEG       39
  252.  
  253. #endif  /* __assembler */
  254. #endif  /* _INTERNAL_IFSTRIP_ */
  255.  
  256. /*
  257.  * Define rounding modes.
  258.  */
  259.  
  260. #ifndef __assembler
  261.  
  262. typedef enum {
  263.     _FpRoundNearest,
  264.     _FpRoundMinusInfinity,
  265.     _FpRoundPlusInfinity,
  266.     _FpRoundChopped
  267. } _FPIEEE_ROUNDING_MODE;
  268.  
  269. typedef enum {
  270.     _FpPrecisionFull,
  271.     _FpPrecision53,
  272.     _FpPrecision24
  273. } _FPIEEE_PRECISION;
  274.  
  275.  
  276. /*
  277.  * Define floating point context record
  278.  */
  279.  
  280. typedef float           _FP32;
  281. typedef double          _FP64;
  282. typedef short           _I16;
  283. typedef int             _I32;
  284. typedef unsigned short  _U16;
  285. typedef unsigned int    _U32;
  286.  
  287. #ifndef _INTERNAL_IFSTRIP_
  288. typedef struct {
  289.     unsigned long W[4];
  290. } _U32ARRAY;
  291. #endif  /* _INTERNAL_IFSTRIP_ */
  292.  
  293. typedef struct {
  294.     unsigned short W[5];
  295. } _FP80;
  296.  
  297. typedef struct {
  298.     unsigned long W[4];
  299. } _FP128;
  300.  
  301. typedef struct {
  302.     unsigned long W[2];
  303. } _I64;
  304.  
  305. typedef struct {
  306.     unsigned long W[2];
  307. } _U64;
  308.  
  309. typedef struct {
  310.     unsigned short W[5];
  311. } _BCD80;
  312.  
  313.  
  314. typedef struct {
  315.     union {
  316.         _FP32        Fp32Value;
  317.         _FP64        Fp64Value;
  318.         _FP80        Fp80Value;
  319.         _FP128       Fp128Value;
  320.         _I16         I16Value;
  321.         _I32         I32Value;
  322.         _I64         I64Value;
  323.         _U16         U16Value;
  324.         _U32         U32Value;
  325.         _U64         U64Value;
  326.         _BCD80       Bcd80Value;
  327.         char         *StringValue;
  328.         int          CompareValue;
  329. #ifndef _INTERNAL_IFSTRIP_
  330.         _U32ARRAY    U32ArrayValue;
  331. #endif  /* _INTERNAL_IFSTRIP_ */
  332.     } Value;
  333.  
  334.     unsigned int OperandValid : 1;
  335.     unsigned int Format : 4;
  336.  
  337. } _FPIEEE_VALUE;
  338.  
  339.  
  340. typedef struct {
  341.     unsigned int Inexact : 1;
  342.     unsigned int Underflow : 1;
  343.     unsigned int Overflow : 1;
  344.     unsigned int ZeroDivide : 1;
  345.     unsigned int InvalidOperation : 1;
  346. } _FPIEEE_EXCEPTION_FLAGS;
  347.  
  348.  
  349. typedef struct {
  350.     unsigned int RoundingMode : 2;
  351.     unsigned int Precision : 3;
  352.     unsigned int Operation :12;
  353.     _FPIEEE_EXCEPTION_FLAGS Cause;
  354.     _FPIEEE_EXCEPTION_FLAGS Enable;
  355.     _FPIEEE_EXCEPTION_FLAGS Status;
  356.     _FPIEEE_VALUE Operand1;
  357.     _FPIEEE_VALUE Operand2;
  358.     _FPIEEE_VALUE Result;
  359. } _FPIEEE_RECORD;
  360.  
  361.  
  362. struct _EXCEPTION_POINTERS;
  363.  
  364. /*
  365.  * Floating point IEEE exception filter routine
  366.  */
  367.  
  368. _CRTIMP int __cdecl _fpieee_flt(
  369.         unsigned long,
  370.         struct _EXCEPTION_POINTERS *,
  371.         int (__cdecl *)(_FPIEEE_RECORD *)
  372.         );
  373.  
  374. #ifdef __cplusplus
  375. }
  376. #endif  /* __cplusplus */
  377.  
  378. #ifdef _MSC_VER
  379. #pragma pack(pop)
  380. #endif  /* _MSC_VER */
  381. #endif  /* __assembler */
  382.  
  383. #endif  /* _INC_FPIEEE */
  384.