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


kni
Author(s): Neuronics AG (see AUTHORS.txt); ROS wrapper by Martin Günther
autogenerated on Mon Oct 6 2014 10:45:33