/[GiNaC]/ginac/numeric.h
ViewVC logotype

Contents of /ginac/numeric.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.45 - (hide annotations)
Thu Feb 15 19:54:55 2001 UTC (12 years, 3 months ago) by cbauer
Branch: MAIN
Changes since 1.44: +0 -14 lines
File MIME type: text/plain
the destructor, copy constructor, and assignment operator (which were the
same for all subclasses of basic, with very few exceptions) are now included
in the GINAC_IMPLEMENT_REGISTERED_CLASS macro; the GINAC_DECLARE_REGISTERED_CLASS
macro also defines these (and other common) member functions

1 cbauer 1.1 /** @file numeric.h
2     *
3 cbauer 1.4 * Makes the interface to the underlying bignum package available. */
4    
5     /*
6 kreckel 1.43 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
7 cbauer 1.2 *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21     */
22 cbauer 1.1
23 cbauer 1.2 #ifndef __GINAC_NUMERIC_H__
24     #define __GINAC_NUMERIC_H__
25 cbauer 1.1
26     #include <strstream>
27 cbauer 1.21 #include "basic.h"
28     #include "ex.h"
29 cbauer 1.1
30 kreckel 1.41 #include <cln/number.h>
31     // forward decln of cln::cl_N, since cln/complex_class.h is not included:
32     namespace cln { class cl_N; }
33    
34     #if defined(G__CINTVERSION) && !defined(__MAKECINT__)
35     // Cint @$#$! doesn't like forward declaring classes used for casting operators
36     // so we have to include the definition of cln::cl_N here, but it is enough to
37     // do so for the compiler, hence the !defined(__MAKECINT__).
38     #include <cln/complex_class.h>
39     #endif
40 cbauer 1.1
41 kreckel 1.22 #ifndef NO_NAMESPACE_GINAC
42 cbauer 1.5 namespace GiNaC {
43 kreckel 1.22 #endif // ndef NO_NAMESPACE_GINAC
44 cbauer 1.5
45     #define HASHVALUE_NUMERIC 0x80000001U
46    
47 cbauer 1.1 /** This class is used to instantiate a global object Digits which
48     * behaves just like Maple's Digits. We need an object rather than a
49     * dumber basic type since as a side-effect we let it change
50     * cl_default_float_format when it gets changed. The only other
51     * meaningful thing to do with it is converting it to an unsigned,
52     * for temprary storing its value e.g. The user must not create an
53     * own working object of this class! Since C++ forces us to make the
54     * class definition visible in order to use an object we put in a
55     * flag which prevents other objects of that class to be created. */
56     class _numeric_digits
57     {
58     // member functions
59     public:
60 cbauer 1.38 _numeric_digits();
61     _numeric_digits& operator=(long prec);
62     operator long();
63     void print(std::ostream & os) const;
64 cbauer 1.1 // member variables
65     private:
66 cbauer 1.38 long digits;
67     static bool too_late;
68 cbauer 1.1 };
69    
70     /** This class is a wrapper around CLN-numbers within the GiNaC class
71     * hierarchy. Objects of this type may directly be created by the user.*/
72     class numeric : public basic
73     {
74 cbauer 1.38 GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)
75 cbauer 1.18
76 cbauer 1.1 // member functions
77    
78 cbauer 1.38 // other constructors
79 cbauer 1.1 public:
80 cbauer 1.38 explicit numeric(int i);
81     explicit numeric(unsigned int i);
82     explicit numeric(long i);
83     explicit numeric(unsigned long i);
84     explicit numeric(long numer, long denom);
85     explicit numeric(double d);
86     explicit numeric(const char *);
87    
88     // functions overriding virtual functions from bases classes
89 cbauer 1.1 public:
90 cbauer 1.38 basic * duplicate() const;
91     void print(std::ostream & os, unsigned precedence=0) const;
92     void printraw(std::ostream & os) const;
93     void printtree(std::ostream & os, unsigned indent) const;
94     void printcsrc(std::ostream & os, unsigned type, unsigned precedence=0) const;
95     bool info(unsigned inf) const;
96     bool has(const ex & other) const;
97     ex eval(int level=0) const;
98     ex evalf(int level=0) const;
99     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
100     ex to_rational(lst &repl_lst) const;
101     numeric integer_content(void) const;
102     ex smod(const numeric &xi) const;
103     numeric max_coefficient(void) const;
104 cbauer 1.1 protected:
105 cbauer 1.38 ex derivative(const symbol & s) const;
106     int compare_same_type(const basic & other) const;
107     bool is_equal_same_type(const basic & other) const;
108     unsigned calchash(void) const;
109 cbauer 1.1
110 cbauer 1.38 // new virtual functions which can be overridden by derived classes
111     // (none)
112 cbauer 1.1
113 cbauer 1.38 // non-virtual functions in this class
114 cbauer 1.1 public:
115 kreckel 1.41 const numeric add(const numeric & other) const;
116     const numeric sub(const numeric & other) const;
117     const numeric mul(const numeric & other) const;
118     const numeric div(const numeric & other) const;
119     const numeric power(const numeric & other) const;
120 cbauer 1.38 const numeric & add_dyn(const numeric & other) const;
121     const numeric & sub_dyn(const numeric & other) const;
122     const numeric & mul_dyn(const numeric & other) const;
123     const numeric & div_dyn(const numeric & other) const;
124     const numeric & power_dyn(const numeric & other) const;
125     const numeric & operator=(int i);
126     const numeric & operator=(unsigned int i);
127     const numeric & operator=(long i);
128     const numeric & operator=(unsigned long i);
129     const numeric & operator=(double d);
130     const numeric & operator=(const char * s);
131 kreckel 1.41 const numeric inverse(void) const;
132 cbauer 1.38 int csgn(void) const;
133     int compare(const numeric & other) const;
134     bool is_equal(const numeric & other) const;
135     bool is_zero(void) const;
136     bool is_positive(void) const;
137     bool is_negative(void) const;
138     bool is_integer(void) const;
139     bool is_pos_integer(void) const;
140     bool is_nonneg_integer(void) const;
141     bool is_even(void) const;
142     bool is_odd(void) const;
143     bool is_prime(void) const;
144     bool is_rational(void) const;
145     bool is_real(void) const;
146     bool is_cinteger(void) const;
147     bool is_crational(void) const;
148     bool operator==(const numeric & other) const;
149     bool operator!=(const numeric & other) const;
150     bool operator<(const numeric & other) const;
151     bool operator<=(const numeric & other) const;
152     bool operator>(const numeric & other) const;
153     bool operator>=(const numeric & other) const;
154     int to_int(void) const;
155     long to_long(void) const;
156     double to_double(void) const;
157 kreckel 1.42 cln::cl_N to_cl_N(void) const;
158 cbauer 1.38 const numeric real(void) const;
159     const numeric imag(void) const;
160     const numeric numer(void) const;
161     const numeric denom(void) const;
162     int int_length(void) const;
163 kreckel 1.41 // converting routines for interfacing with CLN:
164     numeric(const cln::cl_N & z);
165 cbauer 1.1
166     // member variables
167    
168     protected:
169 cbauer 1.38 static unsigned precedence;
170 kreckel 1.41 cln::cl_number value;
171 cbauer 1.1 };
172    
173     // global constants
174    
175     extern const numeric I;
176     extern _numeric_digits Digits;
177    
178 frink 1.26 //#define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)
179 cbauer 1.1 // may have to be changed to ((x)>=0x80000000U)
180 frink 1.26
181     // has been changed
182     //#define is_a_numeric_hash(x) ((x)&0x80000000U)
183 cbauer 1.1
184     // global functions
185    
186 kreckel 1.20 const numeric exp(const numeric & x);
187     const numeric log(const numeric & x);
188     const numeric sin(const numeric & x);
189     const numeric cos(const numeric & x);
190     const numeric tan(const numeric & x);
191     const numeric asin(const numeric & x);
192     const numeric acos(const numeric & x);
193     const numeric atan(const numeric & x);
194     const numeric atan(const numeric & y, const numeric & x);
195     const numeric sinh(const numeric & x);
196     const numeric cosh(const numeric & x);
197     const numeric tanh(const numeric & x);
198     const numeric asinh(const numeric & x);
199     const numeric acosh(const numeric & x);
200     const numeric atanh(const numeric & x);
201 kreckel 1.36 const numeric Li2(const numeric & x);
202 kreckel 1.20 const numeric zeta(const numeric & x);
203 kreckel 1.30 const numeric lgamma(const numeric & x);
204     const numeric tgamma(const numeric & x);
205 kreckel 1.20 const numeric psi(const numeric & x);
206     const numeric psi(const numeric & n, const numeric & x);
207     const numeric factorial(const numeric & n);
208     const numeric doublefactorial(const numeric & n);
209     const numeric binomial(const numeric & n, const numeric & k);
210     const numeric bernoulli(const numeric & n);
211     const numeric fibonacci(const numeric & n);
212 kreckel 1.41 const numeric abs(const numeric & x);
213     const numeric isqrt(const numeric & x);
214     const numeric sqrt(const numeric & x);
215     const numeric abs(const numeric & x);
216     const numeric mod(const numeric & a, const numeric & b);
217     const numeric smod(const numeric & a, const numeric & b);
218     const numeric irem(const numeric & a, const numeric & b);
219     const numeric irem(const numeric & a, const numeric & b, numeric & q);
220     const numeric iquo(const numeric & a, const numeric & b);
221     const numeric iquo(const numeric & a, const numeric & b, numeric & r);
222     const numeric gcd(const numeric & a, const numeric & b);
223     const numeric lcm(const numeric & a, const numeric & b);
224 cbauer 1.1
225     // wrapper functions around member functions
226 kreckel 1.41 inline const numeric pow(const numeric & x, const numeric & y)
227 kreckel 1.16 { return x.power(y); }
228    
229 kreckel 1.41 inline const numeric inverse(const numeric & x)
230 cbauer 1.1 { return x.inverse(); }
231 kreckel 1.6
232 kreckel 1.32 inline int csgn(const numeric & x)
233 kreckel 1.6 { return x.csgn(); }
234 cbauer 1.1
235 kreckel 1.16 inline bool is_zero(const numeric & x)
236 cbauer 1.1 { return x.is_zero(); }
237    
238 kreckel 1.16 inline bool is_positive(const numeric & x)
239 cbauer 1.1 { return x.is_positive(); }
240    
241 kreckel 1.16 inline bool is_integer(const numeric & x)
242 cbauer 1.1 { return x.is_integer(); }
243    
244 kreckel 1.16 inline bool is_pos_integer(const numeric & x)
245 cbauer 1.1 { return x.is_pos_integer(); }
246    
247 kreckel 1.16 inline bool is_nonneg_integer(const numeric & x)
248 cbauer 1.1 { return x.is_nonneg_integer(); }
249    
250 kreckel 1.16 inline bool is_even(const numeric & x)
251 cbauer 1.1 { return x.is_even(); }
252    
253 kreckel 1.16 inline bool is_odd(const numeric & x)
254 cbauer 1.1 { return x.is_odd(); }
255    
256 kreckel 1.16 inline bool is_prime(const numeric & x)
257 cbauer 1.1 { return x.is_prime(); }
258    
259 kreckel 1.16 inline bool is_rational(const numeric & x)
260 cbauer 1.1 { return x.is_rational(); }
261    
262 kreckel 1.16 inline bool is_real(const numeric & x)
263 cbauer 1.1 { return x.is_real(); }
264    
265 kreckel 1.16 inline bool is_cinteger(const numeric & x)
266 kreckel 1.14 { return x.is_cinteger(); }
267    
268 kreckel 1.16 inline bool is_crational(const numeric & x)
269 kreckel 1.14 { return x.is_crational(); }
270 kreckel 1.42
271     inline int to_int(const numeric & x)
272     { return x.to_int(); }
273    
274     inline long to_long(const numeric & x)
275     { return x.to_long(); }
276    
277     inline double to_double(const numeric & x)
278     { return x.to_double(); }
279 kreckel 1.14
280 kreckel 1.32 inline const numeric real(const numeric & x)
281 cbauer 1.1 { return x.real(); }
282    
283 kreckel 1.32 inline const numeric imag(const numeric & x)
284 cbauer 1.1 { return x.imag(); }
285    
286 kreckel 1.32 inline const numeric numer(const numeric & x)
287 cbauer 1.1 { return x.numer(); }
288    
289 kreckel 1.32 inline const numeric denom(const numeric & x)
290 cbauer 1.1 { return x.denom(); }
291    
292 kreckel 1.11 // numeric evaluation functions for class constant objects:
293    
294 cbauer 1.1 ex PiEvalf(void);
295 kreckel 1.31 ex EulerEvalf(void);
296 cbauer 1.1 ex CatalanEvalf(void);
297    
298 kreckel 1.23
299 cbauer 1.5 // utility functions
300 kreckel 1.23 inline const numeric &ex_to_numeric(const ex &e)
301     {
302 cbauer 1.38 return static_cast<const numeric &>(*e.bp);
303 kreckel 1.23 }
304    
305 cbauer 1.1
306 kreckel 1.22 #ifndef NO_NAMESPACE_GINAC
307 cbauer 1.5 } // namespace GiNaC
308 kreckel 1.22 #endif // ndef NO_NAMESPACE_GINAC
309 kreckel 1.41
310     #ifdef __MAKECINT__
311     #pragma link off defined_in cln/number.h;
312     #pragma link off defined_in cln/complex_class.h;
313     #endif
314 cbauer 1.1
315 cbauer 1.2 #endif // ndef __GINAC_NUMERIC_H__

Christian Bauer">Christian Bauer
ViewVC Help
Powered by ViewVC 1.1.15