source: git/ntl/include/NTL/quad_float.h @ 92c0ac

spielwiese
Last change on this file since 92c0ac was 92c0ac, checked in by Hans Schönemann <hannes@…>, 21 years ago
NTL-5.2 git-svn-id: file:///usr/local/Singular/svn/trunk@6320 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.4 KB
Line 
1
2#ifndef NTL_quad_float__H
3#define NTL_quad_float__H
4
5
6/*
7Copyright (C) 1997, 1998, 1999, 2000 Victor Shoup
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23*****************************************************
24
25The quad_float package is derived from the doubledouble package of
26Keith Briggs.  However, the version employed in NTL has been extensively
27modified.  Below, I attach the copyright notice from the original
28doubledouble package, which is currently available at
29
30   http://www.labs.bt.com/people/briggsk2
31
32*****************************************************
33
34Copyright (C) 1997 Keith Martin Briggs
35
36Except where otherwise indicated,
37this program is free software; you can redistribute it and/or
38modify it under the terms of the GNU General Public License
39as published by the Free Software Foundation; either version 2
40of the License, or (at your option) any later version.
41
42This program is distributed in the hope that it will be useful,
43but WITHOUT ANY WARRANTY; without even the implied warranty of
44MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45GNU General Public License for more details.
46
47You should have received a copy of the GNU General Public License
48along with this program; if not, write to the Free Software
49Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
50*/
51
52#include <NTL/ZZ.h>
53
54NTL_OPEN_NNS
55
56
57class quad_float {
58public:
59  double hi, lo;
60
61  // Constructors
62  quad_float() : hi(0), lo(0)  {}
63
64  inline quad_float& operator=(double x);
65
66  static long oprec;
67  static void SetOutputPrecision(long p);
68  static long OutputPrecision() { return oprec; }
69
70  quad_float(double x, double y) : hi(x), lo(y) { } // internal use only
71
72  ~quad_float() {}
73
74};  // end class quad_float
75
76#if (NTL_BITS_PER_LONG < NTL_DOUBLE_PRECISION)
77
78inline quad_float to_quad_float(long n) { return quad_float(n, 0); }
79inline quad_float to_quad_float(unsigned long n) { return quad_float(n, 0); }
80
81#else
82
83quad_float to_quad_float(long n);
84quad_float to_quad_float(unsigned long n);
85
86#endif
87
88#if (NTL_BITS_PER_INT < NTL_DOUBLE_PRECISION)
89
90inline quad_float to_quad_float(int n) { return quad_float(n, 0); }
91inline quad_float to_quad_float(unsigned int n) { return quad_float(n, 0); }
92 
93#else
94
95inline quad_float to_quad_float(int n) 
96   { return to_quad_float(long(n)); }
97inline quad_float to_quad_float(unsigned int n) 
98   { return to_quad_float((unsigned long) n); }
99
100#endif
101
102
103
104inline quad_float to_quad_float(double x) { return quad_float(x, 0); }
105// On platforms with extended doubles, this may result in an
106// improper quad_float object, but it should be converted to a proper
107// one when passed by reference to any of the arithmetic routines,
108// at which time x will be forced to memory.
109
110inline quad_float to_quad_float(float x) 
111   { return to_quad_float(double(x)); }
112
113inline quad_float& quad_float::operator=(double x) 
114   { *this = to_quad_float(x); return *this; }
115
116quad_float operator+(const quad_float&, const quad_float& );
117
118inline quad_float operator+(const quad_float& x, double y )
119   { return x + to_quad_float(y); }
120
121inline quad_float operator+(double x, const quad_float& y)
122   { return to_quad_float(x) + y; }
123
124quad_float operator-(const quad_float&, const quad_float& );
125
126inline quad_float operator-(const quad_float& x, double y )
127   { return x - to_quad_float(y); }
128
129inline quad_float operator-(double x, const quad_float& y)
130   { return to_quad_float(x) - y; }
131
132quad_float operator*(const quad_float&, const quad_float& );
133
134inline quad_float operator*(const quad_float& x, double y )
135   { return x * to_quad_float(y); }
136
137inline quad_float operator*(double x, const quad_float& y)
138   { return to_quad_float(x) * y; }
139
140quad_float operator/(const quad_float&, const quad_float& );
141
142inline quad_float operator/(const quad_float& x, double y )
143   { return x / to_quad_float(y); }
144
145inline quad_float operator/(double x, const quad_float& y)
146   { return to_quad_float(x) / y; }
147
148quad_float operator-(const quad_float& x);
149
150quad_float& operator+= (quad_float& x, const quad_float& y);
151inline quad_float& operator += (quad_float& x, double y)
152   { x += to_quad_float(y); return x; }
153
154quad_float& operator-= (quad_float& x, const quad_float& y);
155inline quad_float& operator-= (quad_float& x, double y)
156   { x -= to_quad_float(y); return x; }
157
158quad_float& operator*= (quad_float& x, const quad_float& y);
159inline quad_float& operator*= (quad_float& x, double y)
160   { x *= to_quad_float(y); return x; }
161
162quad_float& operator/= (quad_float& x, const quad_float& y);
163inline quad_float& operator/= (quad_float& x, double y)
164   { x /= to_quad_float(y); return x; }
165
166inline quad_float& operator++(quad_float& a) { a += 1.0; return a; }
167inline void operator++(quad_float& a, int) { a += 1.0; }
168
169inline quad_float& operator--(quad_float& a) { a -= 1.0; return a; }
170inline void operator--(quad_float& a, int) { a -= 1.0; }
171
172
173long operator> (const quad_float& x, const quad_float& y);
174long operator>=(const quad_float& x, const quad_float& y);
175long operator< (const quad_float& x, const quad_float& y);
176long operator<=(const quad_float& x, const quad_float& y);
177long operator==(const quad_float& x, const quad_float& y);
178long operator!=(const quad_float& x, const quad_float& y);
179
180inline long operator> (const quad_float& x, double y) 
181   { return x > to_quad_float(y); }
182inline long operator> (double x, const quad_float& y)
183   { return to_quad_float(x) > y; }
184
185inline long operator>=(const quad_float& x, double y) 
186   { return x >= to_quad_float(y); }
187inline long operator>=(double x, const quad_float& y)
188   { return to_quad_float(x) >= y; }
189
190inline long operator< (const quad_float& x, double y) 
191   { return x < to_quad_float(y); }
192inline long operator< (double x, const quad_float& y)
193   { return to_quad_float(x) < y; }
194
195inline long operator<=(const quad_float& x, double y) 
196   { return x <= to_quad_float(y); }
197inline long operator<=(double x, const quad_float& y)
198   { return to_quad_float(x) <= y; }
199
200inline long operator!=(const quad_float& x, double y) 
201   { return x != to_quad_float(y); }
202inline long operator!=(double x, const quad_float& y)
203   { return to_quad_float(x) != y; }
204
205inline long operator==(const quad_float& x, double y) 
206   { return x == to_quad_float(y); }
207inline long operator==(double x, const quad_float& y)
208   { return to_quad_float(x) == y; }
209
210
211inline long sign(const quad_float& x){
212  if (x.hi>0.0) return 1; else if (x.hi<0.0) return -1; else return 0;
213}
214
215long compare(const quad_float&, const quad_float&);
216
217inline long compare(const quad_float& x, double y)
218   { return compare(x, to_quad_float(y)); }
219
220inline long compare(double x, const quad_float& y)
221   { return compare(to_quad_float(x), y); }
222
223
224
225NTL_SNS istream& operator >> (NTL_SNS istream&, quad_float&);
226NTL_SNS ostream& operator << (NTL_SNS ostream&, const quad_float&);
227
228
229quad_float sqrt(const quad_float&);
230quad_float floor(const quad_float&);
231quad_float ceil(const quad_float&);
232quad_float trunc(const quad_float&);
233quad_float fabs(const quad_float&);
234
235void power(quad_float&, const quad_float&, long);
236inline quad_float power(const quad_float& x, long e)
237   { quad_float z; power(z, x, e); return z; }
238
239void power2(quad_float&, long);
240inline quad_float power2_quad_float(long e)
241   { quad_float z; power2(z, e); return z; }
242
243
244long to_long(const quad_float&);
245inline int to_int(const quad_float& x) { return int(to_long(x)); }
246
247inline double to_double(const quad_float& x) { return x.hi; }
248
249inline float to_float(const quad_float& x) { return float(x.hi); }
250
251
252inline void conv(quad_float& x, int a) { x = to_quad_float(a); }
253inline void conv(quad_float& x, long a) { x = to_quad_float(a); }
254
255inline void conv(quad_float& x, unsigned int a) { x = to_quad_float(a); }
256inline void conv(quad_float& x, unsigned long a) { x = to_quad_float(a); }
257
258inline void conv(quad_float& x, float a) { x = to_quad_float(a); }
259inline void conv(quad_float& x, double a) { x = to_quad_float(a); }
260
261
262inline void conv(long& x, const quad_float& a) { x = to_long(a); }
263inline void conv(int& x, const quad_float& a) { x = to_int(a); }
264inline void conv(double& x, const quad_float& a) { x = to_double(a); }
265inline void conv(float& x, const quad_float& a) { x = to_float(a); }
266
267void conv(quad_float&, const ZZ&);
268inline quad_float to_quad_float(const ZZ& x)
269   { quad_float z; conv(z, x); return z; }
270
271void conv(ZZ&, const quad_float&);
272inline ZZ to_ZZ(const quad_float& a)
273   { ZZ x; conv(x, a); NTL_OPT_RETURN(ZZ, x); }
274
275inline void conv(quad_float& x, const quad_float& a)
276   { x = a; }
277inline quad_float to_quad_float(const quad_float& a)
278   { return a; }
279
280quad_float to_quad_float(const char *s);
281inline void conv(quad_float& x, const char *s)
282   { x = to_quad_float(s); }
283
284long IsFinite(quad_float *x);
285
286long PrecisionOK();
287
288quad_float ldexp(const quad_float& x, long exp);
289
290quad_float exp(const quad_float& x);
291quad_float log(const quad_float& x);
292
293void random(quad_float& x);
294quad_float random_quad_float();
295
296
297NTL_CLOSE_NNS
298
299#endif
Note: See TracBrowser for help on using the repository browser.