home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / fpieee.h < prev    next >
C/C++ Source or Header  |  1998-06-16  |  5KB  |  270 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
  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
  24.  
  25.  
  26. #ifndef __assembler     /* MIPS ONLY: Protect from assembler */
  27.  
  28. #ifdef  _MSC_VER
  29. /*
  30.  * Currently, all MS C compilers for Win32 platforms default to 8 byte
  31.  * alignment.
  32.  */
  33. #pragma pack(push,8)
  34. #endif  /* _MSC_VER */
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39.  
  40.  
  41.  
  42. /* Define _CRTIMP */
  43.  
  44. #ifndef _CRTIMP
  45. #ifdef  _DLL
  46. #define _CRTIMP __declspec(dllimport)
  47. #else   /* ndef _DLL */
  48. #define _CRTIMP
  49. #endif  /* _DLL */
  50. #endif  /* _CRTIMP */
  51.  
  52.  
  53. /* Define __cdecl for non-Microsoft compilers */
  54.  
  55. #if     ( !defined(_MSC_VER) && !defined(__cdecl) )
  56. #define __cdecl
  57. #endif
  58.  
  59. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  60.  
  61. #ifndef _CRTAPI1
  62. #if    _MSC_VER >= 800 && _M_IX86 >= 300
  63. #define _CRTAPI1 __cdecl
  64. #else
  65. #define _CRTAPI1
  66. #endif
  67. #endif
  68.  
  69. /*
  70.  * Define floating point IEEE compare result values.
  71.  */
  72.  
  73. typedef enum {
  74.     _FpCompareEqual,
  75.     _FpCompareGreater,
  76.     _FpCompareLess,
  77.     _FpCompareUnordered
  78. } _FPIEEE_COMPARE_RESULT;
  79.  
  80. /*
  81.  * Define floating point format and result precision values.
  82.  */
  83.  
  84. typedef enum {
  85.     _FpFormatFp32,
  86.     _FpFormatFp64,
  87.     _FpFormatFp80,
  88.     _FpFormatFp128,
  89.     _FpFormatI16,
  90.     _FpFormatI32,
  91.     _FpFormatI64,
  92.     _FpFormatU16,
  93.     _FpFormatU32,
  94.     _FpFormatU64,
  95.     _FpFormatBcd80,
  96.     _FpFormatCompare,
  97.     _FpFormatString
  98. } _FPIEEE_FORMAT;
  99.  
  100. /*
  101.  * Define operation code values.
  102.  */
  103.  
  104. typedef enum {
  105.     _FpCodeUnspecified,
  106.     _FpCodeAdd,
  107.     _FpCodeSubtract,
  108.     _FpCodeMultiply,
  109.     _FpCodeDivide,
  110.     _FpCodeSquareRoot,
  111.     _FpCodeRemainder,
  112.     _FpCodeCompare,
  113.     _FpCodeConvert,
  114.     _FpCodeRound,
  115.     _FpCodeTruncate,
  116.     _FpCodeFloor,
  117.     _FpCodeCeil,
  118.     _FpCodeAcos,
  119.     _FpCodeAsin,
  120.     _FpCodeAtan,
  121.     _FpCodeAtan2,
  122.     _FpCodeCabs,
  123.     _FpCodeCos,
  124.     _FpCodeCosh,
  125.     _FpCodeExp,
  126.     _FpCodeFabs,
  127.     _FpCodeFmod,
  128.     _FpCodeFrexp,
  129.     _FpCodeHypot,
  130.     _FpCodeLdexp,
  131.     _FpCodeLog,
  132.     _FpCodeLog10,
  133.     _FpCodeModf,
  134.     _FpCodePow,
  135.     _FpCodeSin,
  136.     _FpCodeSinh,
  137.     _FpCodeTan,
  138.     _FpCodeTanh,
  139.     _FpCodeY0,
  140.     _FpCodeY1,
  141.     _FpCodeYn,
  142.     _FpCodeLogb,
  143.     _FpCodeNextafter,
  144.     _FpCodeNegate
  145.  
  146. } _FP_OPERATION_CODE;
  147.  
  148. #endif  /* #ifndef __assembler */
  149.  
  150. /*
  151.  * Define rounding modes.
  152.  */
  153.  
  154. #ifndef __assembler     /* MIPS ONLY: Protect from assembler */
  155.  
  156. typedef enum {
  157.     _FpRoundNearest,
  158.     _FpRoundMinusInfinity,
  159.     _FpRoundPlusInfinity,
  160.     _FpRoundChopped
  161. } _FPIEEE_ROUNDING_MODE;
  162.  
  163. typedef enum {
  164.     _FpPrecisionFull,
  165.     _FpPrecision53,
  166.     _FpPrecision24
  167. } _FPIEEE_PRECISION;
  168.  
  169.  
  170. /*
  171.  * Define floating point context record
  172.  */
  173.  
  174. typedef float           _FP32;
  175. typedef double          _FP64;
  176. typedef short           _I16;
  177. typedef int             _I32;
  178. typedef unsigned short  _U16;
  179. typedef unsigned int    _U32;
  180.  
  181.  
  182. typedef struct {
  183.     unsigned short W[5];
  184. } _FP80;
  185.  
  186. typedef struct {
  187.     unsigned long W[4];
  188. } _FP128;
  189.  
  190. typedef struct {
  191.     unsigned long W[2];
  192. } _I64;
  193.  
  194. typedef struct {
  195.     unsigned long W[2];
  196. } _U64;
  197.  
  198. typedef struct {
  199.     unsigned short W[5];
  200. } _BCD80;
  201.  
  202.  
  203. typedef struct {
  204.     union {
  205.         _FP32        Fp32Value;
  206.         _FP64        Fp64Value;
  207.         _FP80        Fp80Value;
  208.         _FP128       Fp128Value;
  209.         _I16         I16Value;
  210.         _I32         I32Value;
  211.         _I64         I64Value;
  212.         _U16         U16Value;
  213.         _U32         U32Value;
  214.         _U64         U64Value;
  215.         _BCD80       Bcd80Value;
  216.         char         *StringValue;
  217.         int          CompareValue;
  218.     } Value;
  219.  
  220.     unsigned int OperandValid : 1;
  221.     unsigned int Format : 4;
  222.  
  223. } _FPIEEE_VALUE;
  224.  
  225.  
  226. typedef struct {
  227.     unsigned int Inexact : 1;
  228.     unsigned int Underflow : 1;
  229.     unsigned int Overflow : 1;
  230.     unsigned int ZeroDivide : 1;
  231.     unsigned int InvalidOperation : 1;
  232. } _FPIEEE_EXCEPTION_FLAGS;
  233.  
  234.  
  235. typedef struct {
  236.     unsigned int RoundingMode : 2;
  237.     unsigned int Precision : 3;
  238.     unsigned int Operation :12;
  239.     _FPIEEE_EXCEPTION_FLAGS Cause;
  240.     _FPIEEE_EXCEPTION_FLAGS Enable;
  241.     _FPIEEE_EXCEPTION_FLAGS Status;
  242.     _FPIEEE_VALUE Operand1;
  243.     _FPIEEE_VALUE Operand2;
  244.     _FPIEEE_VALUE Result;
  245. } _FPIEEE_RECORD;
  246.  
  247.  
  248. struct _EXCEPTION_POINTERS;
  249.  
  250. /*
  251.  * Floating point IEEE exception filter routine
  252.  */
  253.  
  254. _CRTIMP int __cdecl _fpieee_flt(
  255.         unsigned long,
  256.         struct _EXCEPTION_POINTERS *,
  257.         int (__cdecl *)(_FPIEEE_RECORD *)
  258.         );
  259.  
  260. #ifdef  __cplusplus
  261. }
  262. #endif
  263.  
  264. #ifdef  _MSC_VER
  265. #pragma pack(pop)
  266. #endif  /* _MSC_VER */
  267. #endif  /* #ifndef __assembler */
  268.  
  269. #endif  /* _INC_FPIEEE */
  270.