457
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
457
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
457
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
457
|
26 #endif |
|
27 |
1367
|
28 #include <cfloat> |
|
29 #include <cmath> |
457
|
30 |
|
31 #include "dbleDET.h" |
5904
|
32 #include "lo-mappers.h" |
457
|
33 |
5634
|
34 bool |
457
|
35 DET::value_will_overflow (void) const |
|
36 { |
5634
|
37 return base2 |
5904
|
38 ? (e2 + 1 > xlog2 (DBL_MAX) ? 1 : 0) |
5634
|
39 : (e10 + 1 > log10 (DBL_MAX) ? 1 : 0); |
457
|
40 } |
|
41 |
5634
|
42 bool |
457
|
43 DET::value_will_underflow (void) const |
|
44 { |
5634
|
45 return base2 |
5904
|
46 ? (e2 - 1 < xlog2 (DBL_MIN) ? 1 : 0) |
5634
|
47 : (e10 - 1 < log10 (DBL_MIN) ? 1 : 0); |
457
|
48 } |
|
49 |
5634
|
50 void |
|
51 DET::initialize10 (void) |
457
|
52 { |
5634
|
53 if (c2 != 0.0) |
|
54 { |
5904
|
55 double etmp = e2 / xlog2 (10); |
|
56 e10 = static_cast<int> (xround (etmp)); |
5634
|
57 etmp -= e10; |
|
58 c10 = c2 * pow (10.0, etmp); |
|
59 } |
457
|
60 } |
|
61 |
5634
|
62 void |
|
63 DET::initialize2 (void) |
457
|
64 { |
5634
|
65 if (c10 != 0.0) |
|
66 { |
|
67 double etmp = e10 / log10 (2); |
5904
|
68 e2 = static_cast<int> (xround (etmp)); |
5634
|
69 etmp -= e2; |
5904
|
70 c2 = c10 * xexp2 (etmp); |
5634
|
71 } |
457
|
72 } |
|
73 |
|
74 double |
|
75 DET::value (void) const |
|
76 { |
5904
|
77 return base2 ? c2 * xexp2 (e2) : c10 * pow (10.0, e10); |
457
|
78 } |
|
79 |
|
80 /* |
|
81 ;;; Local Variables: *** |
|
82 ;;; mode: C++ *** |
|
83 ;;; End: *** |
|
84 */ |