| 1 | //$$ precisio.h floating point constants |
|---|
| 2 | |
|---|
| 3 | #ifndef PRECISION_LIB |
|---|
| 4 | #define PRECISION_LIB 0 |
|---|
| 5 | |
|---|
| 6 | #ifdef _STANDARD_ // standard library available |
|---|
| 7 | #include <limits> |
|---|
| 8 | #endif |
|---|
| 9 | |
|---|
| 10 | #ifdef use_namespace |
|---|
| 11 | namespace NEWMAT { |
|---|
| 12 | #endif |
|---|
| 13 | |
|---|
| 14 | #ifdef _STANDARD_ // standard library available |
|---|
| 15 | |
|---|
| 16 | using namespace std; |
|---|
| 17 | |
|---|
| 18 | class FloatingPointPrecision |
|---|
| 19 | { |
|---|
| 20 | public: |
|---|
| 21 | static int Dig() // number of decimal digits or precision |
|---|
| 22 | { return numeric_limits<Real>::digits10 ; } |
|---|
| 23 | |
|---|
| 24 | static Real Epsilon() // smallest number such that 1+Eps!=Eps |
|---|
| 25 | { return numeric_limits<Real>::epsilon(); } |
|---|
| 26 | |
|---|
| 27 | static int Mantissa() // bits in mantisa |
|---|
| 28 | { return numeric_limits<Real>::digits; } |
|---|
| 29 | |
|---|
| 30 | static Real Maximum() // maximum value |
|---|
| 31 | { return numeric_limits<Real>::max(); } |
|---|
| 32 | |
|---|
| 33 | static int MaximumDecimalExponent() // maximum decimal exponent |
|---|
| 34 | { return numeric_limits<Real>::max_exponent10; } |
|---|
| 35 | |
|---|
| 36 | static int MaximumExponent() // maximum binary exponent |
|---|
| 37 | { return numeric_limits<Real>::max_exponent; } |
|---|
| 38 | |
|---|
| 39 | static Real LnMaximum() // natural log of maximum |
|---|
| 40 | { return (Real)log(Maximum()); } |
|---|
| 41 | |
|---|
| 42 | static Real Minimum() // minimum positive value |
|---|
| 43 | { return numeric_limits<Real>::min(); } |
|---|
| 44 | |
|---|
| 45 | static int MinimumDecimalExponent() // minimum decimal exponent |
|---|
| 46 | { return numeric_limits<Real>::min_exponent10; } |
|---|
| 47 | |
|---|
| 48 | static int MinimumExponent() // minimum binary exponent |
|---|
| 49 | { return numeric_limits<Real>::min_exponent; } |
|---|
| 50 | |
|---|
| 51 | static Real LnMinimum() // natural log of minimum |
|---|
| 52 | { return (Real)log(Minimum()); } |
|---|
| 53 | |
|---|
| 54 | static int Radix() // exponent radix |
|---|
| 55 | { return numeric_limits<Real>::radix; } |
|---|
| 56 | |
|---|
| 57 | static int Rounds() // addition rounding (1 = does round) |
|---|
| 58 | { |
|---|
| 59 | return numeric_limits<Real>::round_style == |
|---|
| 60 | round_to_nearest ? 1 : 0; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | #else // _STANDARD_ not defined |
|---|
| 67 | |
|---|
| 68 | #ifndef SystemV // if there is float.h |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | #ifdef USING_FLOAT |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | class FloatingPointPrecision |
|---|
| 75 | { |
|---|
| 76 | public: |
|---|
| 77 | static int Dig() |
|---|
| 78 | { return FLT_DIG; } // number of decimal digits or precision |
|---|
| 79 | |
|---|
| 80 | static Real Epsilon() |
|---|
| 81 | { return FLT_EPSILON; } // smallest number such that 1+Eps!=Eps |
|---|
| 82 | |
|---|
| 83 | static int Mantissa() |
|---|
| 84 | { return FLT_MANT_DIG; } // bits in mantisa |
|---|
| 85 | |
|---|
| 86 | static Real Maximum() |
|---|
| 87 | { return FLT_MAX; } // maximum value |
|---|
| 88 | |
|---|
| 89 | static int MaximumDecimalExponent() |
|---|
| 90 | { return FLT_MAX_10_EXP; } // maximum decimal exponent |
|---|
| 91 | |
|---|
| 92 | static int MaximumExponent() |
|---|
| 93 | { return FLT_MAX_EXP; } // maximum binary exponent |
|---|
| 94 | |
|---|
| 95 | static Real LnMaximum() |
|---|
| 96 | { return (Real)log(Maximum()); } // natural log of maximum |
|---|
| 97 | |
|---|
| 98 | static Real Minimum() |
|---|
| 99 | { return FLT_MIN; } // minimum positive value |
|---|
| 100 | |
|---|
| 101 | static int MinimumDecimalExponent() |
|---|
| 102 | { return FLT_MIN_10_EXP; } // minimum decimal exponent |
|---|
| 103 | |
|---|
| 104 | static int MinimumExponent() |
|---|
| 105 | { return FLT_MIN_EXP; } // minimum binary exponent |
|---|
| 106 | |
|---|
| 107 | static Real LnMinimum() |
|---|
| 108 | { return (Real)log(Minimum()); } // natural log of minimum |
|---|
| 109 | |
|---|
| 110 | static int Radix() |
|---|
| 111 | { return FLT_RADIX; } // exponent radix |
|---|
| 112 | |
|---|
| 113 | static int Rounds() |
|---|
| 114 | { return FLT_ROUNDS; } // addition rounding (1 = does round) |
|---|
| 115 | |
|---|
| 116 | }; |
|---|
| 117 | |
|---|
| 118 | #endif // USING_FLOAT |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | #ifdef USING_DOUBLE |
|---|
| 122 | |
|---|
| 123 | class FloatingPointPrecision |
|---|
| 124 | { |
|---|
| 125 | public: |
|---|
| 126 | |
|---|
| 127 | static int Dig() |
|---|
| 128 | { return DBL_DIG; } // number of decimal digits or precision |
|---|
| 129 | |
|---|
| 130 | static Real Epsilon() |
|---|
| 131 | { return DBL_EPSILON; } // smallest number such that 1+Eps!=Eps |
|---|
| 132 | |
|---|
| 133 | static int Mantissa() |
|---|
| 134 | { return DBL_MANT_DIG; } // bits in mantisa |
|---|
| 135 | |
|---|
| 136 | static Real Maximum() |
|---|
| 137 | { return DBL_MAX; } // maximum value |
|---|
| 138 | |
|---|
| 139 | static int MaximumDecimalExponent() |
|---|
| 140 | { return DBL_MAX_10_EXP; } // maximum decimal exponent |
|---|
| 141 | |
|---|
| 142 | static int MaximumExponent() |
|---|
| 143 | { return DBL_MAX_EXP; } // maximum binary exponent |
|---|
| 144 | |
|---|
| 145 | static Real LnMaximum() |
|---|
| 146 | { return (Real)log(Maximum()); } // natural log of maximum |
|---|
| 147 | |
|---|
| 148 | static Real Minimum() |
|---|
| 149 | { |
|---|
| 150 | //#ifdef __BCPLUSPLUS__ |
|---|
| 151 | // return 2.225074e-308; // minimum positive value |
|---|
| 152 | //#else |
|---|
| 153 | return DBL_MIN; |
|---|
| 154 | //#endif |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | static int MinimumDecimalExponent() |
|---|
| 158 | { return DBL_MIN_10_EXP; } // minimum decimal exponent |
|---|
| 159 | |
|---|
| 160 | static int MinimumExponent() |
|---|
| 161 | { return DBL_MIN_EXP; } // minimum binary exponent |
|---|
| 162 | |
|---|
| 163 | static Real LnMinimum() |
|---|
| 164 | { return (Real)log(Minimum()); } // natural log of minimum |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | static int Radix() |
|---|
| 168 | { return FLT_RADIX; } // exponent radix |
|---|
| 169 | |
|---|
| 170 | static int Rounds() |
|---|
| 171 | { return FLT_ROUNDS; } // addition rounding (1 = does round) |
|---|
| 172 | |
|---|
| 173 | }; |
|---|
| 174 | |
|---|
| 175 | #endif // USING_DOUBLE |
|---|
| 176 | |
|---|
| 177 | #else // if there is no float.h |
|---|
| 178 | |
|---|
| 179 | #ifdef USING_FLOAT |
|---|
| 180 | |
|---|
| 181 | class FloatingPointPrecision |
|---|
| 182 | { |
|---|
| 183 | public: |
|---|
| 184 | |
|---|
| 185 | static Real Epsilon() |
|---|
| 186 | { return pow(2.0,(int)(1-FSIGNIF)); } |
|---|
| 187 | // smallest number such that 1+Eps!=Eps |
|---|
| 188 | |
|---|
| 189 | static Real Maximum() |
|---|
| 190 | { return MAXFLOAT; } // maximum value |
|---|
| 191 | |
|---|
| 192 | static Real LnMaximum() |
|---|
| 193 | { return (Real)log(Maximum()); } // natural log of maximum |
|---|
| 194 | |
|---|
| 195 | static Real Minimum() |
|---|
| 196 | { return MINFLOAT; } // minimum positive value |
|---|
| 197 | |
|---|
| 198 | static Real LnMinimum() |
|---|
| 199 | { return (Real)log(Minimum()); } // natural log of minimum |
|---|
| 200 | |
|---|
| 201 | }; |
|---|
| 202 | |
|---|
| 203 | #endif // USING_FLOAT |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | #ifdef USING_DOUBLE |
|---|
| 207 | |
|---|
| 208 | class FloatingPointPrecision |
|---|
| 209 | { |
|---|
| 210 | public: |
|---|
| 211 | |
|---|
| 212 | static Real Epsilon() |
|---|
| 213 | { return pow(2.0,(int)(1-DSIGNIF)); } |
|---|
| 214 | // smallest number such that 1+Eps!=Eps |
|---|
| 215 | |
|---|
| 216 | static Real Maximum() |
|---|
| 217 | { return MAXDOUBLE; } // maximum value |
|---|
| 218 | |
|---|
| 219 | static Real LnMaximum() |
|---|
| 220 | { return LN_MAXDOUBLE; } // natural log of maximum |
|---|
| 221 | |
|---|
| 222 | static Real Minimum() |
|---|
| 223 | { return MINDOUBLE; } |
|---|
| 224 | |
|---|
| 225 | static Real LnMinimum() |
|---|
| 226 | { return LN_MINDOUBLE; } // natural log of minimum |
|---|
| 227 | }; |
|---|
| 228 | |
|---|
| 229 | #endif // USING_DOUBLE |
|---|
| 230 | |
|---|
| 231 | #endif // SystemV |
|---|
| 232 | |
|---|
| 233 | #endif // _STANDARD_ |
|---|
| 234 | |
|---|
| 235 | #ifdef use_namespace |
|---|
| 236 | } |
|---|
| 237 | #endif // use_namespace |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | #endif // PRECISION_LIB |
|---|