precisio.h
Go to the documentation of this file.00001
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()
00021 { return std::numeric_limits<Real>::digits10 ; }
00022
00023 static Real Epsilon()
00024 { return std::numeric_limits<Real>::epsilon(); }
00025
00026 static int Mantissa()
00027 { return std::numeric_limits<Real>::digits; }
00028
00029 static Real Maximum()
00030 { return std::numeric_limits<Real>::max(); }
00031
00032 static int MaximumDecimalExponent()
00033 { return std::numeric_limits<Real>::max_exponent10; }
00034
00035 static int MaximumExponent()
00036 { return std::numeric_limits<Real>::max_exponent; }
00037
00038 static Real LnMaximum()
00039 { return (Real)std::log(Maximum()); }
00040
00041 static Real Minimum()
00042 { return std::numeric_limits<Real>::min(); }
00043
00044 static int MinimumDecimalExponent()
00045 { return std::numeric_limits<Real>::min_exponent10; }
00046
00047 static int MinimumExponent()
00048 { return std::numeric_limits<Real>::min_exponent; }
00049
00050 static Real LnMinimum()
00051 { return (Real)std::log(Minimum()); }
00052
00053 static int Radix()
00054 { return std::numeric_limits<Real>::radix; }
00055
00056 static int Rounds()
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; }
00078
00079 static Real Epsilon()
00080 { return FLT_EPSILON; }
00081
00082 static int Mantissa()
00083 { return FLT_MANT_DIG; }
00084
00085 static Real Maximum()
00086 { return FLT_MAX; }
00087
00088 static int MaximumDecimalExponent()
00089 { return FLT_MAX_10_EXP; }
00090
00091 static int MaximumExponent()
00092 { return FLT_MAX_EXP; }
00093
00094 static Real LnMaximum()
00095 { return (Real)log(Maximum()); }
00096
00097 static Real Minimum()
00098 { return FLT_MIN; }
00099
00100 static int MinimumDecimalExponent()
00101 { return FLT_MIN_10_EXP; }
00102
00103 static int MinimumExponent()
00104 { return FLT_MIN_EXP; }
00105
00106 static Real LnMinimum()
00107 { return (Real)log(Minimum()); }
00108
00109 static int Radix()
00110 { return FLT_RADIX; }
00111
00112 static int Rounds()
00113 { return FLT_ROUNDS; }
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; }
00128
00129 static Real Epsilon()
00130 { return DBL_EPSILON; }
00131
00132 static int Mantissa()
00133 { return DBL_MANT_DIG; }
00134
00135 static Real Maximum()
00136 { return DBL_MAX; }
00137
00138 static int MaximumDecimalExponent()
00139 { return DBL_MAX_10_EXP; }
00140
00141 static int MaximumExponent()
00142 { return DBL_MAX_EXP; }
00143
00144 static Real LnMaximum()
00145 { return (Real)log(Maximum()); }
00146
00147 static Real Minimum()
00148 {
00149
00150
00151
00152 return DBL_MIN;
00153
00154 }
00155
00156 static int MinimumDecimalExponent()
00157 { return DBL_MIN_10_EXP; }
00158
00159 static int MinimumExponent()
00160 { return DBL_MIN_EXP; }
00161
00162 static Real LnMinimum()
00163 { return (Real)log(Minimum()); }
00164
00165
00166 static int Radix()
00167 { return FLT_RADIX; }
00168
00169 static int Rounds()
00170 { return FLT_ROUNDS; }
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
00187
00188 static Real Maximum()
00189 { return MAXFLOAT; }
00190
00191 static Real LnMaximum()
00192 { return (Real)log(Maximum()); }
00193
00194 static Real Minimum()
00195 { return MINFLOAT; }
00196
00197 static Real LnMinimum()
00198 { return (Real)log(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
00214
00215 static Real Maximum()
00216 { return MAXDOUBLE; }
00217
00218 static Real LnMaximum()
00219 { return LN_MAXDOUBLE; }
00220
00221 static Real Minimum()
00222 { return MINDOUBLE; }
00223
00224 static Real LnMinimum()
00225 { return LN_MINDOUBLE; }
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