home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / n / newmat06.zip / PRECISIO.H < prev    next >
C/C++ Source or Header  |  1992-11-27  |  3KB  |  124 lines

  1. //$$ precisio.h                          floating point constants
  2.  
  3. #ifndef PRECISION_LIB
  4. #define PRECISION_LIB 0
  5.  
  6. #ifndef SystemV                    // if there is float.h
  7.  
  8.  
  9. #ifdef USING_FLOAT
  10.  
  11.  
  12. class FloatingPointPrecision
  13. {
  14. public:
  15.    static int Dig()
  16.       { return FLT_DIG; }        // number of decimal digits or precision
  17.    static Real Epsilon()
  18.       { return FLT_EPSILON; }    // smallest number such that 1+Eps!=Eps
  19.    static int Mantissa()
  20.       { return FLT_MANT_DIG; }   // bits in mantisa
  21.    static Real Maximum()
  22.       { return FLT_MAX; }        // maximum value
  23.    static int MaximumDecimalExponent()
  24.       { return FLT_MAX_10_EXP; } // maximum decimal exponent
  25.    static int MaximumExponent()
  26.       { return FLT_MAX_EXP; }    // maximum binary exponent
  27.    static Real Minimum()
  28.       { return FLT_MIN; }        // minimum positive value
  29.    static int MinimumDecimalExponent()
  30.       { return FLT_MIN_10_EXP; } // minimum decimal exponent
  31.    static int MinimumExponent()
  32.       { return FLT_MIN_EXP; }    // minimum binary exponent
  33.    static int Radix()
  34.       { return FLT_RADIX; }      // exponent radix
  35.    static int Rounds()
  36.       { return FLT_ROUNDS; }     // addition rounding (1 = does round)
  37.    FREE_CHECK(FloatingPointPrecision)
  38. };
  39.  
  40. #endif
  41.  
  42.  
  43. #ifdef USING_DOUBLE
  44.  
  45. class FloatingPointPrecision
  46. {
  47. public:
  48.    static int Dig()
  49.       { return DBL_DIG; }        // number of decimal digits or precision
  50.    static Real Epsilon()
  51.       { return DBL_EPSILON; }    // smallest number such that 1+Eps!=Eps
  52.    static int Mantissa()
  53.       { return DBL_MANT_DIG; }   // bits in mantisa
  54.    static Real Maximum()
  55.       { return DBL_MAX; }        // maximum value
  56.    static int MaximumDecimalExponent()
  57.       { return DBL_MAX_10_EXP; } // maximum decimal exponent
  58.    static int MaximumExponent()
  59.       { return DBL_MAX_EXP; }    // maximum binary exponent
  60.    static Real Minimum()
  61.    {
  62. #ifdef __BCPLUSPLUS__
  63.        return 2.225074e-308;     // minimum positive value
  64. #else
  65.        return DBL_MIN;
  66. #endif
  67.    }
  68.    static int MinimumDecimalExponent()
  69.       { return DBL_MIN_10_EXP; } // minimum decimal exponent
  70.    static int MinimumExponent()
  71.       { return DBL_MIN_EXP; }    // minimum binary exponent
  72.    static int Radix()
  73.       { return FLT_RADIX; }      // exponent radix
  74.    static int Rounds()
  75.       { return FLT_ROUNDS; }     // addition rounding (1 = does round)
  76.    FREE_CHECK(FloatingPointPrecision)
  77. };
  78.  
  79. #endif
  80.  
  81. #endif
  82.  
  83. #ifdef SystemV                    // if there is no float.h
  84.  
  85. #ifdef USING_FLOAT
  86.  
  87. class FloatingPointPrecision
  88. {
  89. public:
  90.    static Real Epsilon()
  91.       { return pow(2.0,1-FSIGNIF); }  // smallest number such that 1+Eps!=Eps
  92.    static Real Maximum()
  93.       { return MAXFLOAT; }        // maximum value
  94.    static Real Minimum()
  95.       { return MINFLOAT; }        // minimum positive value
  96.    FREE_CHECK(FloatingPointPrecision)
  97. };
  98.  
  99. #endif
  100.  
  101.  
  102. #ifdef USING_DOUBLE
  103.  
  104. class FloatingPointPrecision
  105. {
  106. public:
  107.    static Real Epsilon()
  108.       { return pow(2.0,1-DSIGNIF); }  // smallest number such that 1+Eps!=Eps
  109.    static Real Maximum()
  110.       { return MAXDOUBLE; }          // maximum value
  111.    static Real Minimum()
  112.       { return MINDOUBLE; }
  113.    FREE_CHECK(FloatingPointPrecision)
  114. };
  115.  
  116. #endif
  117.  
  118. #endif
  119.  
  120.  
  121.  
  122.  
  123. #endif
  124.