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"
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>
00025 #endif
00026
00027 using namespace std;
00028
00030 class FloatingPointPrecision
00031 {
00032 public:
00033 static int Dig()
00034 { return numeric_limits<Real>::digits10 ; }
00035
00036 static Real Epsilon()
00037 { return numeric_limits<Real>::epsilon(); }
00038
00039 static int Mantissa()
00040 { return numeric_limits<Real>::digits; }
00041
00042 static Real Maximum()
00043 { return numeric_limits<Real>::max(); }
00044
00045 static int MaximumDecimalExponent()
00046 { return numeric_limits<Real>::max_exponent10; }
00047
00048 static int MaximumExponent()
00049 { return numeric_limits<Real>::max_exponent; }
00050
00051 static Real LnMaximum()
00052 { return (Real)log(Maximum()); }
00053
00054 static Real Minimum()
00055 { return numeric_limits<Real>::min(); }
00056
00057 static int MinimumDecimalExponent()
00058 { return numeric_limits<Real>::min_exponent10; }
00059
00060 static int MinimumExponent()
00061 { return numeric_limits<Real>::min_exponent; }
00062
00063 static Real LnMinimum()
00064 { return (Real)log(Minimum()); }
00065
00066 static int Radix()
00067 { return numeric_limits<Real>::radix; }
00068
00069 static int Rounds()
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; }
00090
00091 static Real Epsilon()
00092 { return FLT_EPSILON; }
00093
00094 static int Mantissa()
00095 { return FLT_MANT_DIG; }
00096
00097 static Real Maximum()
00098 { return FLT_MAX; }
00099
00100 static int MaximumDecimalExponent()
00101 { return FLT_MAX_10_EXP; }
00102
00103 static int MaximumExponent()
00104 { return FLT_MAX_EXP; }
00105
00106 static Real LnMaximum()
00107 { return (Real)log(Maximum()); }
00108
00109 static Real Minimum()
00110 { return FLT_MIN; }
00111
00112 static int MinimumDecimalExponent()
00113 { return FLT_MIN_10_EXP; }
00114
00115 static int MinimumExponent()
00116 { return FLT_MIN_EXP; }
00117
00118 static Real LnMinimum()
00119 { return (Real)log(Minimum()); }
00120
00121 static int Radix()
00122 { return FLT_RADIX; }
00123
00124 static int Rounds()
00125 { return FLT_ROUNDS; }
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; }
00141
00142 static Real Epsilon()
00143 { return DBL_EPSILON; }
00144
00145 static int Mantissa()
00146 { return DBL_MANT_DIG; }
00147
00148 static Real Maximum()
00149 { return DBL_MAX; }
00150
00151 static int MaximumDecimalExponent()
00152 { return DBL_MAX_10_EXP; }
00153
00154 static int MaximumExponent()
00155 { return DBL_MAX_EXP; }
00156
00157 static Real LnMaximum()
00158 { return (Real)log(Maximum()); }
00159
00160 static Real Minimum()
00161 {
00162
00163
00164
00165 return DBL_MIN;
00166
00167 }
00168
00169 static int MinimumDecimalExponent()
00170 { return DBL_MIN_10_EXP; }
00171
00172 static int MinimumExponent()
00173 { return DBL_MIN_EXP; }
00174
00175 static Real LnMinimum()
00176 { return (Real)log(Minimum()); }
00177
00178
00179 static int Radix()
00180 { return FLT_RADIX; }
00181
00182 static int Rounds()
00183 { return FLT_ROUNDS; }
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
00206
00207 static Real Maximum()
00208 { return MAXFLOAT; }
00209
00210 static Real LnMaximum()
00211 { return (Real)log(Maximum()); }
00212
00213 static Real Minimum()
00214 { return MINFLOAT; }
00215
00216 static Real LnMinimum()
00217 { return (Real)log(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
00234
00235 static Real Maximum()
00236 { return MAXDOUBLE; }
00237
00238 static Real LnMaximum()
00239 { return LN_MAXDOUBLE; }
00240
00241 static Real Minimum()
00242 { return MINDOUBLE; }
00243
00244 static Real LnMinimum()
00245 { return LN_MINDOUBLE; }
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