source: git/ntl/doc/xdouble.txt @ 6ce030f

spielwiese
Last change on this file since 6ce030f was e6caf81, checked in by Hans Schönemann <hannes@…>, 20 years ago
*hannes: 5.3.2 git-svn-id: file:///usr/local/Singular/svn/trunk@7472 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.9 KB
Line 
1
2
3/**************************************************************************\
4
5MODULE: xdouble
6
7SUMMARY:
8
9The class xdouble is used to represent floating point numbers with the
10same precision as a 'double', but with extended exponent range
11(offering a few more bits than that of a 'long' for the exponent).
12
13The programming interface for xdoubles is almost identical to that of
14ordinary doubles.
15
16
17\**************************************************************************/
18
19#include <NTL/ZZ.h>
20
21
22class xdouble {
23
24public:
25
26xdouble(); // = 0
27
28xdouble(const xdouble& a);  // copy constructor
29
30xdouble& operator=(const xdouble& a);  // assignment operator
31xdouble& operator=(double a);
32
33~xdouble();
34
35
36double mantissa() const;  // read-only access to mantissa
37long exponent() const;  // read-only access to exponenent
38
39
40
41static void SetOutputPrecision(long p);
42// This sets the number of decimal digits to be output.  Default is
43// 10.
44
45static long OutputPrecision();
46// returns current output precision.
47
48};
49
50
51
52/**************************************************************************\
53
54                             Arithmetic Operations
55
56The following are the standard arithmetic operators, whose meaning should
57be clear.
58
59\**************************************************************************/
60
61
62xdouble operator+(const xdouble& a, const xdouble& b);
63xdouble operator-(const xdouble& a, const xdouble& b);
64xdouble operator*(const xdouble& a, const xdouble& b);
65xdouble operator/(const xdouble& a, const xdouble& b);
66
67// PROMOTIONS: +, -, *, / promote double to xdouble on (a, b).
68
69xdouble operator-(const xdouble& a);
70
71xdouble& operator+=(xdouble& a, const xdouble& b);
72xdouble& operator+=(xdouble& a, double b);
73
74xdouble& operator-=(xdouble& a, const xdouble& b);
75xdouble& operator-=(xdouble& a, double b);
76
77xdouble& operator*=(xdouble& a, const xdouble& b);
78xdouble& operator*=(xdouble& a, double b);
79
80xdouble& operator/=(xdouble& a, const xdouble& b);
81xdouble& operator/=(xdouble& a, xdouble b);
82
83xdouble& operator++(xdouble& a); // prefix
84void operator++(xdouble& a, int); // postfix
85
86xdouble& operator--(xdouble& a); // prefix
87void operator--(xdouble& a, int); // postfix
88
89
90
91/**************************************************************************\
92
93                                  Comparison
94
95\**************************************************************************/
96
97long sign(const xdouble& a);
98// returns sign (+1, -1, 0) of a
99
100long compare(const xdouble& a, const xdouble& b);
101// returns sign of a - b
102
103long operator==(const xdouble& a, const xdouble& b);
104long operator!=(const xdouble& a, const xdouble& b);
105long operator<=(const xdouble& a, const xdouble& b);
106long operator>=(const xdouble& a, const xdouble& b);
107long operator <(const xdouble& a, const xdouble& b);
108long operator >(const xdouble& a, const xdouble& b);
109
110// PROMOTIONS: compare and operators ==, ..., > promote double to xdouble
111// on (a, b).
112
113
114
115/**************************************************************************\
116
117                               Input/Output
118Input Syntax:
119
120<number>: [ "-" ] <unsigned-number>
121<unsigned-number>: <dotted-number> [ <e-part> ] | <e-part>
122<dotted-number>: <digits> | <digits> "." <digits> | "." <digits> | <digits> "."
123<digits>: <digit> <digits> | <digit>
124<digit>: "0" | ... | "9"
125<e-part>: ( "E" | "e" ) [ "+" | "-" ] <digits>
126
127Examples of valid input:
128
12917 1.5 0.5 .5  5.  -.5 e10 e-10 e+10 1.5e10 .5e10 .5E10
130
131Note that the number of decimal digits of precision that are used
132for output can be set to any number p >= 1 by calling
133the routine xdouble::SetOutputPrecision(p). 
134The default value of p is 10.
135The current value of p is returned by a call to xdouble::OutputPrecision().
136
137\**************************************************************************/
138
139
140
141ostream& operator<<(ostream& s, const xdouble& a);
142
143istream& operator>>(istream& s, xdouble& x);
144
145
146/**************************************************************************\
147
148                                  Miscellaneous
149
150\**************************************************************************/
151
152
153
154xdouble trunc(const xdouble& a);  // returns integer obtained by truncating
155xdouble floor(const xdouble& a);  // returns greatest integer <= a
156xdouble ceil(const xdouble& a);   // returns smallest integer >= a
157xdouble fabs(const xdouble& a);   // returns |a|
158xdouble sqrt(const xdouble& a);   // returns a^{1/2}; error is raised if a < 0
159
160double log(const xdouble& a);  // returns log(a) (note return val is double!)
161xdouble xexp(double a);        // returns exp(a) (note argument is double!)
162
163
164
165void power(xdouble& z, const xdouble& a, const ZZ& e);
166xdouble power(const xdouble& a, const ZZ& e);
167
168void power(xdouble& z, const xdouble& a, long e);
169xdouble power(const xdouble& a, long e);
170// z = a^e, e may be negative
171
172void power2(xdouble& z, long e);
173xdouble power2_xdouble(long e);
174// z = 2^e, e may be negative
175
176void MulAdd(xdouble& z, const xdouble& a, const xdouble& b, const xdouble& c);
177xdouble MulAdd(const xdouble& a, const xdouble& b, const xdouble& c);
178// z = a + b*c, but faster
179
180void MulSub(xdouble& z, const xdouble& a, const xdouble& b, const xdouble& c);
181xdouble MulSub(const xdouble& a, const xdouble& b, const xdouble& c);
182// z = a - b*c, but faster
183
184
185/**************************************************************************\
186
187Implementation details:
188
189An xdouble is represented as a mantissa/exponent pair (x, e), where x
190is a double and e is a long.  The real number represented by (x, e) is
191x * NTL_XD_BOUND^e, where
192
193  NTL_XD_BOUND = NTL_XD_HBOUND^2, and
194  NTL_XD_HBOUND = 2^{(max(NTL_DOUBLE_PRECISION,NTL_BITS_PER_LONG)+4)}.
195
196Also, the mantissa x satisfies 1/NTL_XD_HBOUND <= |x| <= NTL_XD_HBOUND, except
197that the number 0 is always represented as (0, 0). 
198Both NTL_XD_BOUND and NTL_XD_HBOUND are macros defined in <NTL/xdouble.h>.
199
200SIZE INVARIANT: |e| < 2^(NTL_BITS_PER_LONG-4).
201
202\**************************************************************************/
203
Note: See TracBrowser for help on using the repository browser.