source: ntrip/trunk/BNC/newmat/precisio.h@ 10581

Last change on this file since 10581 was 9434, checked in by stuerze, 4 years ago

newmat is reverted to its stable version 10 because version 11beta was not working with mac compilers

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