home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / limits < prev    next >
Text File  |  1998-06-16  |  14KB  |  443 lines

  1. // limits standard header
  2.  
  3. #if     _MSC_VER > 1000
  4. #pragma once
  5. #endif
  6.  
  7. #ifndef _LIMITS_
  8. #define _LIMITS_
  9. #include <ymath.h>
  10. #include <cfloat>
  11. #include <climits>
  12. #include <cmath>
  13. #include <cwchar>
  14. #include <xstddef>
  15.  
  16. #ifdef  _MSC_VER
  17. #pragma pack(push,8)
  18. #endif  /* _MSC_VER */
  19. //    ASSUMES:
  20. //    wraparound 2's complement integer arithmetic w/o traps
  21. //    all CHAR_BITs of each byte used by integers
  22. //    IEC559 (IEEE 754) floating-point arithmetic
  23. //    floating-point errors can trap
  24. //    tinyness detected before floating-point rounding
  25. _STD_BEGIN
  26.         // ENUM float_round_style
  27. typedef enum {
  28.     round_indeterminate = -1, round_toward_zero = 0,
  29.     round_to_nearest = 1, round_toward_infinity = 2,
  30.     round_toward_neg_infinity = 3} float_round_style;
  31.         // STRUCT _Num_base
  32. struct _CRTIMP _Num_base {
  33.     _STCONS(bool, has_denorm, false);
  34.     _STCONS(bool, has_denorm_loss, false);
  35.     _STCONS(bool, has_infinity, false);
  36.     _STCONS(bool, has_quiet_NaN, false);
  37.     _STCONS(bool, has_signaling_NaN, false);
  38.     _STCONS(bool, is_bounded, false);
  39.     _STCONS(bool, is_exact, false);
  40.     _STCONS(bool, is_iec559, false);
  41.     _STCONS(bool, is_integer, false);
  42.     _STCONS(bool, is_modulo, false);
  43.     _STCONS(bool, is_signed, false);
  44.     _STCONS(bool, is_specialized, false);
  45.     _STCONS(bool, tinyness_before, false);
  46.     _STCONS(bool, traps, false);
  47.     _STCONS(float_round_style, round_style, round_toward_zero);
  48.     _STCONS(int, digits, 0);
  49.     _STCONS(int, digits10, 0);
  50.     _STCONS(int, max_exponent, 0);
  51.     _STCONS(int, max_exponent10, 0);
  52.     _STCONS(int, min_exponent, 0);
  53.     _STCONS(int, min_exponent10, 0);
  54.     _STCONS(int, radix, 0);
  55.     };
  56.         // TEMPLATE CLASS numeric_limits
  57. template<class _Ty> class numeric_limits : public _Num_base {
  58. public:
  59.     static _Ty (__cdecl min)() _THROW0()
  60.         {return (_Ty(0)); }
  61.     static _Ty (__cdecl max)() _THROW0()
  62.         {return (_Ty(0)); }
  63.     static _Ty __cdecl epsilon() _THROW0()
  64.         {return (_Ty(0)); }
  65.     static _Ty __cdecl round_error() _THROW0()
  66.         {return (_Ty(0)); }
  67.     static _Ty __cdecl denorm_min() _THROW0()
  68.         {return (_Ty(0)); }
  69.     static _Ty __cdecl infinity() _THROW0()
  70.         {return (_Ty(0)); }
  71.     static _Ty __cdecl quiet_NaN() _THROW0()
  72.         {return (_Ty(0)); }
  73.     static _Ty __cdecl signaling_NaN() _THROW0()
  74.         {return (_Ty(0)); }
  75.     };
  76.         // STRUCT _Num_int_base
  77. struct _CRTIMP _Num_int_base : public _Num_base {
  78.     _STCONS(bool, is_bounded, true);
  79.     _STCONS(bool, is_exact, true);
  80.     _STCONS(bool, is_integer, true);
  81.     _STCONS(bool, is_modulo, true);
  82.     _STCONS(bool, is_specialized, true);
  83.     _STCONS(int, radix, 2);
  84.     };
  85.         // STRUCT _Num_float_base
  86. struct _CRTIMP _Num_float_base : public _Num_base {
  87.     _STCONS(bool, has_denorm, true);
  88.     _STCONS(bool, has_denorm_loss, true);
  89.     _STCONS(bool, has_infinity, true);
  90.     _STCONS(bool, has_quiet_NaN, true);
  91.     _STCONS(bool, has_signaling_NaN, true);
  92.     _STCONS(bool, is_bounded, true);
  93.     _STCONS(bool, is_exact, false);
  94.     _STCONS(bool, is_iec559, true);
  95.     _STCONS(bool, is_integer, false);
  96.     _STCONS(bool, is_modulo, false);
  97.     _STCONS(bool, is_signed, true);
  98.     _STCONS(bool, is_specialized, true);
  99.     _STCONS(bool, tinyness_before, true);
  100.     _STCONS(bool, traps, true);
  101.     _STCONS(float_round_style, round_style, round_to_nearest);
  102.     _STCONS(int, radix, FLT_RADIX);
  103.     };
  104.         // CLASS numeric_limits<char>
  105. class _CRTIMP numeric_limits<char> : public _Num_int_base {
  106. public:
  107.     typedef char _Ty;
  108.     static _Ty (__cdecl min)() _THROW0()
  109.         {return (CHAR_MIN); }
  110.     static _Ty (__cdecl max)() _THROW0()
  111.         {return (CHAR_MAX); }
  112.     static _Ty __cdecl epsilon() _THROW0()
  113.         {return (0); }
  114.     static _Ty __cdecl round_error() _THROW0()
  115.         {return (0); }
  116.     static _Ty __cdecl denorm_min() _THROW0()
  117.         {return (0); }
  118.     static _Ty __cdecl infinity() _THROW0()
  119.         {return (0); }
  120.     static _Ty __cdecl quiet_NaN() _THROW0()
  121.         {return (0); }
  122.     static _Ty __cdecl signaling_NaN() _THROW0()
  123.         {return (0); }
  124.     _STCONS(bool, is_signed, CHAR_MIN < 0);
  125.     _STCONS(int, digits, CHAR_BIT - (CHAR_MIN < 0 ? 1 : 0));
  126.     _STCONS(int, digits10, (CHAR_BIT - (CHAR_MIN < 0 ? 1 : 0))
  127.         * 301L / 1000);
  128.     };
  129.         // CLASS numeric_limits<_Bool>
  130. class _CRTIMP numeric_limits<_Bool> : public _Num_int_base {
  131. public:
  132.     typedef bool _Ty;
  133.     static _Ty (__cdecl min)() _THROW0()
  134.         {return (false); }
  135.     static _Ty (__cdecl max)() _THROW0()
  136.         {return (true); }
  137.     static _Ty __cdecl epsilon() _THROW0()
  138.         {return (0); }
  139.     static _Ty __cdecl round_error() _THROW0()
  140.         {return (0); }
  141.     static _Ty __cdecl denorm_min() _THROW0()
  142.         {return (0); }
  143.     static _Ty __cdecl infinity() _THROW0()
  144.         {return (0); }
  145.     static _Ty __cdecl quiet_NaN() _THROW0()
  146.         {return (0); }
  147.     static _Ty __cdecl signaling_NaN() _THROW0()
  148.         {return (0); }
  149.     _STCONS(bool, is_signed, false);
  150.     _STCONS(int, digits, 1);
  151.     _STCONS(int, digits10, 0);
  152.     };
  153.         // CLASS numeric_limits<signed char>
  154. class _CRTIMP numeric_limits<signed char> : public _Num_int_base {
  155. public:
  156.     typedef signed char _Ty;
  157.     static _Ty (__cdecl min)() _THROW0()
  158.         {return (SCHAR_MIN); }
  159.     static _Ty (__cdecl max)() _THROW0()
  160.         {return (SCHAR_MAX); }
  161.     static _Ty __cdecl epsilon() _THROW0()
  162.         {return (0); }
  163.     static _Ty __cdecl round_error() _THROW0()
  164.         {return (0); }
  165.     static _Ty __cdecl denorm_min() _THROW0()
  166.         {return (0); }
  167.     static _Ty __cdecl infinity() _THROW0()
  168.         {return (0); }
  169.     static _Ty __cdecl quiet_NaN() _THROW0()
  170.         {return (0); }
  171.     static _Ty __cdecl signaling_NaN() _THROW0()
  172.         {return (0); }
  173.     _STCONS(bool, is_signed, true);
  174.     _STCONS(int, digits, CHAR_BIT - 1);
  175.     _STCONS(int, digits10, (CHAR_BIT - 1) * 301L / 1000);
  176.     };
  177.         // CLASS numeric_limits<unsigned char>
  178. class _CRTIMP numeric_limits<unsigned char> : public _Num_int_base {
  179. public:
  180.     typedef unsigned char _Ty;
  181.     static _Ty (__cdecl min)() _THROW0()
  182.         {return (0); }
  183.     static _Ty (__cdecl max)() _THROW0()
  184.         {return (UCHAR_MAX); }
  185.     static _Ty __cdecl epsilon() _THROW0()
  186.         {return (0); }
  187.     static _Ty __cdecl round_error() _THROW0()
  188.         {return (0); }
  189.     static _Ty __cdecl denorm_min() _THROW0()
  190.         {return (0); }
  191.     static _Ty __cdecl infinity() _THROW0()
  192.         {return (0); }
  193.     static _Ty __cdecl quiet_NaN() _THROW0()
  194.         {return (0); }
  195.     static _Ty __cdecl signaling_NaN() _THROW0()
  196.         {return (0); }
  197.     _STCONS(bool, is_signed, false);
  198.     _STCONS(int, digits, CHAR_BIT);
  199.     _STCONS(int, digits10, (CHAR_BIT) * 301L / 1000);
  200.     };
  201.         // CLASS numeric_limits<short>
  202. class _CRTIMP numeric_limits<short> : public _Num_int_base {
  203. public:
  204.     typedef short _Ty;
  205.     static _Ty (__cdecl min)() _THROW0()
  206.         {return (SHRT_MIN); }
  207.     static _Ty (__cdecl max)() _THROW0()
  208.         {return (SHRT_MAX); }
  209.     static _Ty __cdecl epsilon() _THROW0()
  210.         {return (0); }
  211.     static _Ty __cdecl round_error() _THROW0()
  212.         {return (0); }
  213.     static _Ty __cdecl denorm_min() _THROW0()
  214.         {return (0); }
  215.     static _Ty __cdecl infinity() _THROW0()
  216.         {return (0); }
  217.     static _Ty __cdecl quiet_NaN() _THROW0()
  218.         {return (0); }
  219.     static _Ty __cdecl signaling_NaN() _THROW0()
  220.         {return (0); }
  221.     _STCONS(bool, is_signed, true);
  222.     _STCONS(int, digits, CHAR_BIT * sizeof (short) - 1);
  223.     _STCONS(int, digits10, (CHAR_BIT * sizeof (short) - 1)
  224.         * 301L / 1000);
  225.     };
  226.         // CLASS numeric_limits<unsigned short>
  227. class _CRTIMP numeric_limits<unsigned short> : public _Num_int_base {
  228. public:
  229.     typedef unsigned short _Ty;
  230.     static _Ty (__cdecl min)() _THROW0()
  231.         {return (0); }
  232.     static _Ty (__cdecl max)() _THROW0()
  233.         {return (USHRT_MAX); }
  234.     static _Ty __cdecl epsilon() _THROW0()
  235.         {return (0); }
  236.     static _Ty __cdecl round_error() _THROW0()
  237.         {return (0); }
  238.     static _Ty __cdecl denorm_min() _THROW0()
  239.         {return (0); }
  240.     static _Ty __cdecl infinity() _THROW0()
  241.         {return (0); }
  242.     static _Ty __cdecl quiet_NaN() _THROW0()
  243.         {return (0); }
  244.     static _Ty __cdecl signaling_NaN() _THROW0()
  245.         {return (0); }
  246.     _STCONS(bool, is_signed, false);
  247.     _STCONS(int, digits, CHAR_BIT * sizeof (unsigned short));
  248.     _STCONS(int, digits10, (CHAR_BIT * sizeof (unsigned short))
  249.         * 301L / 1000);
  250.     };
  251.         // CLASS numeric_limits<int>
  252. class _CRTIMP numeric_limits<int> : public _Num_int_base {
  253. public:
  254.     typedef int _Ty;
  255.     static _Ty (__cdecl min)() _THROW0()
  256.         {return (INT_MIN); }
  257.     static _Ty (__cdecl max)() _THROW0()
  258.         {return (INT_MAX); }
  259.     static _Ty __cdecl epsilon() _THROW0()
  260.         {return (0); }
  261.     static _Ty __cdecl round_error() _THROW0()
  262.         {return (0); }
  263.     static _Ty __cdecl denorm_min() _THROW0()
  264.         {return (0); }
  265.     static _Ty __cdecl infinity() _THROW0()
  266.         {return (0); }
  267.     static _Ty __cdecl quiet_NaN() _THROW0()
  268.         {return (0); }
  269.     static _Ty __cdecl signaling_NaN() _THROW0()
  270.         {return (0); }
  271.     _STCONS(bool, is_signed, true);
  272.     _STCONS(int, digits, CHAR_BIT * sizeof (int) - 1);
  273.     _STCONS(int, digits10, (CHAR_BIT * sizeof (int) - 1)
  274.         * 301L / 1000);
  275.     };
  276.         // CLASS numeric_limits<unsigned int>
  277. class _CRTIMP numeric_limits<unsigned int> : public _Num_int_base {
  278. public:
  279.     typedef unsigned int _Ty;
  280.     static _Ty (__cdecl min)() _THROW0()
  281.         {return (0); }
  282.     static _Ty (__cdecl max)() _THROW0()
  283.         {return (UINT_MAX); }
  284.     static _Ty __cdecl epsilon() _THROW0()
  285.         {return (0); }
  286.     static _Ty __cdecl round_error() _THROW0()
  287.         {return (0); }
  288.     static _Ty __cdecl denorm_min() _THROW0()
  289.         {return (0); }
  290.     static _Ty __cdecl infinity() _THROW0()
  291.         {return (0); }
  292.     static _Ty __cdecl quiet_NaN() _THROW0()
  293.         {return (0); }
  294.     static _Ty __cdecl signaling_NaN() _THROW0()
  295.         {return (0); }
  296.     _STCONS(bool, is_signed, false);
  297.     _STCONS(int, digits, CHAR_BIT * sizeof (unsigned int));
  298.     _STCONS(int, digits10, (CHAR_BIT * sizeof (unsigned int))
  299.         * 301L / 1000);
  300.     };
  301.         // CLASS numeric_limits<long>
  302. class _CRTIMP numeric_limits<long> : public _Num_int_base {
  303. public:
  304.     typedef long _Ty;
  305.     static _Ty (__cdecl min)() _THROW0()
  306.         {return (LONG_MIN); }
  307.     static _Ty (__cdecl max)() _THROW0()
  308.         {return (LONG_MAX); }
  309.     static _Ty __cdecl epsilon() _THROW0()
  310.         {return (0); }
  311.     static _Ty __cdecl round_error() _THROW0()
  312.         {return (0); }
  313.     static _Ty __cdecl denorm_min() _THROW0()
  314.         {return (0); }
  315.     static _Ty __cdecl infinity() _THROW0()
  316.         {return (0); }
  317.     static _Ty __cdecl quiet_NaN() _THROW0()
  318.         {return (0); }
  319.     static _Ty __cdecl signaling_NaN() _THROW0()
  320.         {return (0); }
  321.     _STCONS(bool, is_signed, true);
  322.     _STCONS(int, digits, CHAR_BIT * sizeof (long) - 1);
  323.     _STCONS(int, digits10, (CHAR_BIT * sizeof (long) - 1)
  324.         * 301L / 1000);
  325.     };
  326.         // CLASS numeric_limits<unsigned long>
  327. class _CRTIMP numeric_limits<unsigned long> : public _Num_int_base {
  328. public:
  329.     typedef unsigned long _Ty;
  330.     static _Ty (__cdecl min)() _THROW0()
  331.         {return (0); }
  332.     static _Ty (__cdecl max)() _THROW0()
  333.         {return (ULONG_MAX); }
  334.     static _Ty __cdecl epsilon() _THROW0()
  335.         {return (0); }
  336.     static _Ty __cdecl round_error() _THROW0()
  337.         {return (0); }
  338.     static _Ty __cdecl denorm_min() _THROW0()
  339.         {return (0); }
  340.     static _Ty __cdecl infinity() _THROW0()
  341.         {return (0); }
  342.     static _Ty __cdecl quiet_NaN() _THROW0()
  343.         {return (0); }
  344.     static _Ty __cdecl signaling_NaN() _THROW0()
  345.         {return (0); }
  346.     _STCONS(bool, is_signed, false);
  347.     _STCONS(int, digits, CHAR_BIT * sizeof (unsigned long));
  348.     _STCONS(int, digits10, (CHAR_BIT * sizeof (unsigned long))
  349.         * 301L / 1000);
  350.     };
  351.         // CLASS numeric_limits<float>
  352. class _CRTIMP numeric_limits<float> : public _Num_float_base {
  353. public:
  354.     typedef float _Ty;
  355.     static _Ty (__cdecl min)() _THROW0()
  356.         {return (FLT_MIN); }
  357.     static _Ty (__cdecl max)() _THROW0()
  358.         {return (FLT_MAX); }
  359.     static _Ty __cdecl epsilon() _THROW0()
  360.         {return (FLT_EPSILON); }
  361.     static _Ty __cdecl round_error() _THROW0()
  362.         {return (0.5); }
  363.     static _Ty __cdecl denorm_min() _THROW0()
  364.         {return (_FDenorm._F); }
  365.     static _Ty __cdecl infinity() _THROW0()
  366.         {return (_FInf._F); }
  367.     static _Ty __cdecl quiet_NaN() _THROW0()
  368.         {return (_FNan._F); }
  369.     static _Ty __cdecl signaling_NaN() _THROW0()
  370.         {return (_FSnan._F); }
  371.     _STCONS(int, digits, FLT_MANT_DIG);
  372.     _STCONS(int, digits10, FLT_DIG);
  373.     _STCONS(int, max_exponent, FLT_MAX_EXP);
  374.     _STCONS(int, max_exponent10, FLT_MAX_10_EXP);
  375.     _STCONS(int, min_exponent, FLT_MIN_EXP);
  376.     _STCONS(int, min_exponent10, FLT_MIN_10_EXP);
  377.     };
  378.         // CLASS numeric_limits<double>
  379. class _CRTIMP numeric_limits<double> : public _Num_float_base {
  380. public:
  381.     typedef double _Ty;
  382.     static _Ty (__cdecl min)() _THROW0()
  383.         {return (DBL_MIN); }
  384.     static _Ty (__cdecl max)() _THROW0()
  385.         {return (DBL_MAX); }
  386.     static _Ty __cdecl epsilon() _THROW0()
  387.         {return (DBL_EPSILON); }
  388.     static _Ty __cdecl round_error() _THROW0()
  389.         {return (0.5); }
  390.     static _Ty __cdecl denorm_min() _THROW0()
  391.         {return (_Denorm._D); }
  392.     static _Ty __cdecl infinity() _THROW0()
  393.         {return (_Inf._D); }
  394.     static _Ty __cdecl quiet_NaN() _THROW0()
  395.         {return (_Nan._D); }
  396.     static _Ty __cdecl signaling_NaN() _THROW0()
  397.         {return (_Snan._D); }
  398.     _STCONS(int, digits, DBL_MANT_DIG);
  399.     _STCONS(int, digits10, DBL_DIG);
  400.     _STCONS(int, max_exponent, DBL_MAX_EXP);
  401.     _STCONS(int, max_exponent10, DBL_MAX_10_EXP);
  402.     _STCONS(int, min_exponent, DBL_MIN_EXP);
  403.     _STCONS(int, min_exponent10, DBL_MIN_10_EXP);
  404.     };
  405.         // CLASS numeric_limits<long double>
  406. class _CRTIMP numeric_limits<long double> : public _Num_float_base {
  407. public:
  408.     typedef long double _Ty;
  409.     static _Ty (__cdecl min)() _THROW0()
  410.         {return (LDBL_MIN); }
  411.     static _Ty (__cdecl max)() _THROW0()
  412.         {return (LDBL_MAX); }
  413.     static _Ty __cdecl epsilon() _THROW0()
  414.         {return (LDBL_EPSILON); }
  415.     static _Ty __cdecl round_error() _THROW0()
  416.         {return (0.5); }
  417.     static _Ty __cdecl denorm_min() _THROW0()
  418.         {return (_LDenorm._L); }
  419.     static _Ty __cdecl infinity() _THROW0()
  420.         {return (_LInf._L); }
  421.     static _Ty __cdecl quiet_NaN() _THROW0()
  422.         {return (_LNan._L); }
  423.     static _Ty __cdecl signaling_NaN() _THROW0()
  424.         {return (_LSnan._L); }
  425.     _STCONS(int, digits, LDBL_MANT_DIG);
  426.     _STCONS(int, digits10, LDBL_DIG);
  427.     _STCONS(int, max_exponent, LDBL_MAX_EXP);
  428.     _STCONS(int, max_exponent10, LDBL_MAX_10_EXP);
  429.     _STCONS(int, min_exponent, LDBL_MIN_EXP);
  430.     _STCONS(int, min_exponent10, LDBL_MIN_10_EXP);
  431.     };
  432. _STD_END
  433. #ifdef  _MSC_VER
  434. #pragma pack(pop)
  435. #endif  /* _MSC_VER */
  436.  
  437. #endif /* _LIMITS_ */
  438.  
  439. /*
  440.  * Copyright (c) 1995 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  441.  * Consult your license regarding permissions and restrictions.
  442.  */
  443.