Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

precisio.h

Go to the documentation of this file.
00001 //$$ precisio.h                          floating point constants
00002 
00003 #ifndef PRECISION_LIB
00004 #define PRECISION_LIB 0
00005 
00006 #ifdef _STANDARD_                 // standard library available
00007 #include <limits>
00008 #include <cmath>
00009 #endif
00010 
00011 #ifdef use_namespace
00012 namespace NEWMAT {
00013 #endif
00014 
00015 #ifdef _STANDARD_                 // standard library available
00016 
00017 class FloatingPointPrecision
00018 {
00019 public:
00020    static int Dig()              // number of decimal digits or precision
00021       { return std::numeric_limits<Real>::digits10 ; }
00022 
00023    static Real Epsilon()         // smallest number such that 1+Eps!=Eps
00024       { return std::numeric_limits<Real>::epsilon(); }
00025 
00026    static int Mantissa()         // bits in mantisa
00027       { return std::numeric_limits<Real>::digits; }
00028 
00029    static Real Maximum()         // maximum value
00030       { return std::numeric_limits<Real>::max(); }
00031 
00032    static int MaximumDecimalExponent()  // maximum decimal exponent
00033       { return std::numeric_limits<Real>::max_exponent10; }
00034 
00035    static int MaximumExponent()  // maximum binary exponent
00036       { return std::numeric_limits<Real>::max_exponent; }
00037 
00038    static Real LnMaximum()       // natural log of maximum
00039       { return (Real)std::log(Maximum()); }
00040 
00041    static Real Minimum()         // minimum positive value
00042       { return std::numeric_limits<Real>::min(); } 
00043 
00044    static int MinimumDecimalExponent() // minimum decimal exponent
00045       { return std::numeric_limits<Real>::min_exponent10; }
00046 
00047    static int MinimumExponent()  // minimum binary exponent
00048       { return std::numeric_limits<Real>::min_exponent; }
00049 
00050    static Real LnMinimum()       // natural log of minimum
00051       { return (Real)std::log(Minimum()); }
00052 
00053    static int Radix()            // exponent radix
00054       { return std::numeric_limits<Real>::radix; }
00055 
00056    static int Rounds()           // addition rounding (1 = does round)
00057    {
00058     return std::numeric_limits<Real>::round_style ==
00059      std::round_to_nearest ? 1 : 0;
00060    }
00061 
00062 };
00063 
00064 
00065 #else                              // _STANDARD_ not defined
00066 
00067 #ifndef SystemV                    // if there is float.h
00068 
00069 
00070 #ifdef USING_FLOAT
00071 
00072 
00073 class FloatingPointPrecision
00074 {
00075 public:
00076    static int Dig()
00077       { return FLT_DIG; }        // number of decimal digits or precision
00078 
00079    static Real Epsilon()
00080       { return FLT_EPSILON; }    // smallest number such that 1+Eps!=Eps
00081 
00082    static int Mantissa()
00083       { return FLT_MANT_DIG; }   // bits in mantisa
00084 
00085    static Real Maximum()
00086       { return FLT_MAX; }        // maximum value
00087 
00088    static int MaximumDecimalExponent()
00089       { return FLT_MAX_10_EXP; } // maximum decimal exponent
00090 
00091    static int MaximumExponent()
00092       { return FLT_MAX_EXP; }    // maximum binary exponent
00093 
00094    static Real LnMaximum()
00095       { return (Real)log(Maximum()); } // natural log of maximum
00096 
00097    static Real Minimum()
00098       { return FLT_MIN; }        // minimum positive value
00099 
00100    static int MinimumDecimalExponent()
00101       { return FLT_MIN_10_EXP; } // minimum decimal exponent
00102 
00103    static int MinimumExponent()
00104       { return FLT_MIN_EXP; }    // minimum binary exponent
00105 
00106    static Real LnMinimum()
00107       { return (Real)log(Minimum()); } // natural log of minimum
00108 
00109    static int Radix()
00110       { return FLT_RADIX; }      // exponent radix
00111 
00112    static int Rounds()
00113       { return FLT_ROUNDS; }     // addition rounding (1 = does round)
00114 
00115 };
00116 
00117 #endif                           // USING_FLOAT
00118 
00119 
00120 #ifdef USING_DOUBLE
00121 
00122 class FloatingPointPrecision
00123 {
00124 public:
00125 
00126    static int Dig()
00127       { return DBL_DIG; }        // number of decimal digits or precision
00128 
00129    static Real Epsilon()
00130       { return DBL_EPSILON; }    // smallest number such that 1+Eps!=Eps
00131 
00132    static int Mantissa()
00133       { return DBL_MANT_DIG; }   // bits in mantisa
00134 
00135    static Real Maximum()
00136       { return DBL_MAX; }        // maximum value
00137 
00138    static int MaximumDecimalExponent()
00139       { return DBL_MAX_10_EXP; } // maximum decimal exponent
00140 
00141    static int MaximumExponent()
00142       { return DBL_MAX_EXP; }    // maximum binary exponent
00143 
00144    static Real LnMaximum()
00145       { return (Real)log(Maximum()); } // natural log of maximum
00146 
00147    static Real Minimum()
00148    {
00149 //#ifdef __BCPLUSPLUS__
00150 //       return 2.225074e-308;     // minimum positive value
00151 //#else
00152        return DBL_MIN;
00153 //#endif
00154    }
00155 
00156    static int MinimumDecimalExponent()
00157       { return DBL_MIN_10_EXP; } // minimum decimal exponent
00158 
00159    static int MinimumExponent()
00160       { return DBL_MIN_EXP; }    // minimum binary exponent
00161 
00162    static Real LnMinimum()
00163       { return (Real)log(Minimum()); } // natural log of minimum
00164 
00165 
00166    static int Radix()
00167       { return FLT_RADIX; }      // exponent radix
00168 
00169    static int Rounds()
00170       { return FLT_ROUNDS; }     // addition rounding (1 = does round)
00171 
00172 };
00173 
00174 #endif                             // USING_DOUBLE
00175 
00176 #else                              // if there is no float.h
00177 
00178 #ifdef USING_FLOAT
00179 
00180 class FloatingPointPrecision
00181 {
00182 public:
00183 
00184    static Real Epsilon()
00185       { return pow(2.0,(int)(1-FSIGNIF)); }
00186                                    // smallest number such that 1+Eps!=Eps
00187 
00188    static Real Maximum()
00189       { return MAXFLOAT; }            // maximum value
00190 
00191    static Real LnMaximum()
00192       { return (Real)log(Maximum()); }  // natural log of maximum
00193 
00194    static Real Minimum()
00195       { return MINFLOAT; }             // minimum positive value
00196 
00197    static Real LnMinimum()
00198       { return (Real)log(Minimum()); }  // natural log of minimum
00199 
00200 };
00201 
00202 #endif                                  // USING_FLOAT
00203 
00204 
00205 #ifdef USING_DOUBLE
00206 
00207 class FloatingPointPrecision
00208 {
00209 public:
00210 
00211    static Real Epsilon()
00212       { return pow(2.0,(int)(1-DSIGNIF)); }
00213                                       // smallest number such that 1+Eps!=Eps
00214 
00215    static Real Maximum()
00216       { return MAXDOUBLE; }           // maximum value
00217 
00218    static Real LnMaximum()
00219       { return LN_MAXDOUBLE; }        // natural log of maximum
00220 
00221    static Real Minimum()
00222       { return MINDOUBLE; }
00223 
00224    static Real LnMinimum()
00225       { return LN_MINDOUBLE; }        // natural log of minimum
00226 };
00227 
00228 #endif                                // USING_DOUBLE
00229 
00230 #endif                                // SystemV
00231 
00232 #endif                                // _STANDARD_
00233 
00234 #ifdef use_namespace
00235 }
00236 #endif                                // use_namespace
00237 
00238 
00239 
00240 #endif                                // PRECISION_LIB

newmat11b
Generated Mon May 9 04:54:18 2016 by Doxygen 1.6.3