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

Contents of /ginac/numeric.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.42 - (hide annotations)
Fri Dec 15 17:47:51 2000 UTC (12 years, 5 months ago) by kreckel
Branch: MAIN
CVS Tags: release_0-7-0
Changes since 1.41: +10 -1 lines
File MIME type: text/plain
- utils.cpp, version.h.in: add version information to the library itself.
- numeric.*: It was not a good idea to have a cast from numeric to cl_N,
  make a method to_cl_N, instead, in order not to confuse compilers.

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.17 * GiNaC Copyright (C) 1999-2000 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 // friends
77 kreckel 1.41 // (none)
78 cbauer 1.1
79     // member functions
80    
81 cbauer 1.38 // default constructor, destructor, copy constructor assignment
82     // operator and helpers
83 cbauer 1.1 public:
84 cbauer 1.38 numeric();
85     ~numeric();
86     numeric(const numeric & other);
87     const numeric & operator=(const numeric & other);
88 cbauer 1.1 protected:
89 cbauer 1.38 void copy(const numeric & other);
90     void destroy(bool call_parent);
91 cbauer 1.1
92 cbauer 1.38 // other constructors
93 cbauer 1.1 public:
94 cbauer 1.38 explicit numeric(int i);
95     explicit numeric(unsigned int i);
96     explicit numeric(long i);
97     explicit numeric(unsigned long i);
98     explicit numeric(long numer, long denom);
99     explicit numeric(double d);
100     explicit numeric(const char *);
101    
102     // functions overriding virtual functions from bases classes
103 cbauer 1.1 public:
104 cbauer 1.38 basic * duplicate() const;
105     void print(std::ostream & os, unsigned precedence=0) const;
106     void printraw(std::ostream & os) const;
107     void printtree(std::ostream & os, unsigned indent) const;
108     void printcsrc(std::ostream & os, unsigned type, unsigned precedence=0) const;
109     bool info(unsigned inf) const;
110     bool has(const ex & other) const;
111     ex eval(int level=0) const;
112     ex evalf(int level=0) const;
113     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
114     ex to_rational(lst &repl_lst) const;
115     numeric integer_content(void) const;
116     ex smod(const numeric &xi) const;
117     numeric max_coefficient(void) const;
118 cbauer 1.1 protected:
119 cbauer 1.38 ex derivative(const symbol & s) const;
120     int compare_same_type(const basic & other) const;
121     bool is_equal_same_type(const basic & other) const;
122     unsigned calchash(void) const;
123 cbauer 1.1
124 cbauer 1.38 // new virtual functions which can be overridden by derived classes
125     // (none)
126 cbauer 1.1
127 cbauer 1.38 // non-virtual functions in this class
128 cbauer 1.1 public:
129 kreckel 1.41 const numeric add(const numeric & other) const;
130     const numeric sub(const numeric & other) const;
131     const numeric mul(const numeric & other) const;
132     const numeric div(const numeric & other) const;
133     const numeric power(const numeric & other) const;
134 cbauer 1.38 const numeric & add_dyn(const numeric & other) const;
135     const numeric & sub_dyn(const numeric & other) const;
136     const numeric & mul_dyn(const numeric & other) const;
137     const numeric & div_dyn(const numeric & other) const;
138     const numeric & power_dyn(const numeric & other) const;
139     const numeric & operator=(int i);
140     const numeric & operator=(unsigned int i);
141     const numeric & operator=(long i);
142     const numeric & operator=(unsigned long i);
143     const numeric & operator=(double d);
144     const numeric & operator=(const char * s);
145 kreckel 1.41 const numeric inverse(void) const;
146 cbauer 1.38 int csgn(void) const;
147     int compare(const numeric & other) const;
148     bool is_equal(const numeric & other) const;
149     bool is_zero(void) const;
150     bool is_positive(void) const;
151     bool is_negative(void) const;
152     bool is_integer(void) const;
153     bool is_pos_integer(void) const;
154     bool is_nonneg_integer(void) const;
155     bool is_even(void) const;
156     bool is_odd(void) const;
157     bool is_prime(void) const;
158     bool is_rational(void) const;
159     bool is_real(void) const;
160     bool is_cinteger(void) const;
161     bool is_crational(void) const;
162     bool operator==(const numeric & other) const;
163     bool operator!=(const numeric & other) const;
164     bool operator<(const numeric & other) const;
165     bool operator<=(const numeric & other) const;
166     bool operator>(const numeric & other) const;
167     bool operator>=(const numeric & other) const;
168     int to_int(void) const;
169     long to_long(void) const;
170     double to_double(void) const;
171 kreckel 1.42 cln::cl_N to_cl_N(void) const;
172 cbauer 1.38 const numeric real(void) const;
173     const numeric imag(void) const;
174     const numeric numer(void) const;
175     const numeric denom(void) const;
176     int int_length(void) const;
177 kreckel 1.41 // converting routines for interfacing with CLN:
178     numeric(const cln::cl_N & z);
179 cbauer 1.1
180     // member variables
181    
182     protected:
183 cbauer 1.38 static unsigned precedence;
184 kreckel 1.41 cln::cl_number value;
185 cbauer 1.1 };
186    
187     // global constants
188    
189     extern const numeric some_numeric;
190     extern const numeric I;
191 kreckel 1.40 extern const std::type_info & typeid_numeric;
192 cbauer 1.1 extern _numeric_digits Digits;
193    
194 frink 1.26 //#define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)
195 cbauer 1.1 // may have to be changed to ((x)>=0x80000000U)
196 frink 1.26
197     // has been changed
198     //#define is_a_numeric_hash(x) ((x)&0x80000000U)
199 cbauer 1.1
200     // global functions
201    
202 kreckel 1.20 const numeric exp(const numeric & x);
203     const numeric log(const numeric & x);
204     const numeric sin(const numeric & x);
205     const numeric cos(const numeric & x);
206     const numeric tan(const numeric & x);
207     const numeric asin(const numeric & x);
208     const numeric acos(const numeric & x);
209     const numeric atan(const numeric & x);
210     const numeric atan(const numeric & y, const numeric & x);
211     const numeric sinh(const numeric & x);
212     const numeric cosh(const numeric & x);
213     const numeric tanh(const numeric & x);
214     const numeric asinh(const numeric & x);
215     const numeric acosh(const numeric & x);
216     const numeric atanh(const numeric & x);
217 kreckel 1.36 const numeric Li2(const numeric & x);
218 kreckel 1.20 const numeric zeta(const numeric & x);
219 kreckel 1.30 const numeric lgamma(const numeric & x);
220     const numeric tgamma(const numeric & x);
221 kreckel 1.20 const numeric psi(const numeric & x);
222     const numeric psi(const numeric & n, const numeric & x);
223     const numeric factorial(const numeric & n);
224     const numeric doublefactorial(const numeric & n);
225     const numeric binomial(const numeric & n, const numeric & k);
226     const numeric bernoulli(const numeric & n);
227     const numeric fibonacci(const numeric & n);
228 kreckel 1.41 const numeric abs(const numeric & x);
229     const numeric isqrt(const numeric & x);
230     const numeric sqrt(const numeric & x);
231     const numeric abs(const numeric & x);
232     const numeric mod(const numeric & a, const numeric & b);
233     const numeric smod(const numeric & a, const numeric & b);
234     const numeric irem(const numeric & a, const numeric & b);
235     const numeric irem(const numeric & a, const numeric & b, numeric & q);
236     const numeric iquo(const numeric & a, const numeric & b);
237     const numeric iquo(const numeric & a, const numeric & b, numeric & r);
238     const numeric gcd(const numeric & a, const numeric & b);
239     const numeric lcm(const numeric & a, const numeric & b);
240 cbauer 1.1
241     // wrapper functions around member functions
242 kreckel 1.41 inline const numeric pow(const numeric & x, const numeric & y)
243 kreckel 1.16 { return x.power(y); }
244    
245 kreckel 1.41 inline const numeric inverse(const numeric & x)
246 cbauer 1.1 { return x.inverse(); }
247 kreckel 1.6
248 kreckel 1.32 inline int csgn(const numeric & x)
249 kreckel 1.6 { return x.csgn(); }
250 cbauer 1.1
251 kreckel 1.16 inline bool is_zero(const numeric & x)
252 cbauer 1.1 { return x.is_zero(); }
253    
254 kreckel 1.16 inline bool is_positive(const numeric & x)
255 cbauer 1.1 { return x.is_positive(); }
256    
257 kreckel 1.16 inline bool is_integer(const numeric & x)
258 cbauer 1.1 { return x.is_integer(); }
259    
260 kreckel 1.16 inline bool is_pos_integer(const numeric & x)
261 cbauer 1.1 { return x.is_pos_integer(); }
262    
263 kreckel 1.16 inline bool is_nonneg_integer(const numeric & x)
264 cbauer 1.1 { return x.is_nonneg_integer(); }
265    
266 kreckel 1.16 inline bool is_even(const numeric & x)
267 cbauer 1.1 { return x.is_even(); }
268    
269 kreckel 1.16 inline bool is_odd(const numeric & x)
270 cbauer 1.1 { return x.is_odd(); }
271    
272 kreckel 1.16 inline bool is_prime(const numeric & x)
273 cbauer 1.1 { return x.is_prime(); }
274    
275 kreckel 1.16 inline bool is_rational(const numeric & x)
276 cbauer 1.1 { return x.is_rational(); }
277    
278 kreckel 1.16 inline bool is_real(const numeric & x)
279 cbauer 1.1 { return x.is_real(); }
280    
281 kreckel 1.16 inline bool is_cinteger(const numeric & x)
282 kreckel 1.14 { return x.is_cinteger(); }
283    
284 kreckel 1.16 inline bool is_crational(const numeric & x)
285 kreckel 1.14 { return x.is_crational(); }
286 kreckel 1.42
287     inline int to_int(const numeric & x)
288     { return x.to_int(); }
289    
290     inline long to_long(const numeric & x)
291     { return x.to_long(); }
292    
293     inline double to_double(const numeric & x)
294     { return x.to_double(); }
295 kreckel 1.14
296 kreckel 1.32 inline const numeric real(const numeric & x)
297 cbauer 1.1 { return x.real(); }
298    
299 kreckel 1.32 inline const numeric imag(const numeric & x)
300 cbauer 1.1 { return x.imag(); }
301    
302 kreckel 1.32 inline const numeric numer(const numeric & x)
303 cbauer 1.1 { return x.numer(); }
304    
305 kreckel 1.32 inline const numeric denom(const numeric & x)
306 cbauer 1.1 { return x.denom(); }
307    
308 kreckel 1.11 // numeric evaluation functions for class constant objects:
309    
310 cbauer 1.1 ex PiEvalf(void);
311 kreckel 1.31 ex EulerEvalf(void);
312 cbauer 1.1 ex CatalanEvalf(void);
313    
314 kreckel 1.23
315 cbauer 1.5 // utility functions
316 kreckel 1.23 inline const numeric &ex_to_numeric(const ex &e)
317     {
318 cbauer 1.38 return static_cast<const numeric &>(*e.bp);
319 kreckel 1.23 }
320    
321 cbauer 1.1
322 kreckel 1.22 #ifndef NO_NAMESPACE_GINAC
323 cbauer 1.5 } // namespace GiNaC
324 kreckel 1.22 #endif // ndef NO_NAMESPACE_GINAC
325 kreckel 1.41
326     #ifdef __MAKECINT__
327     #pragma link off defined_in cln/number.h;
328     #pragma link off defined_in cln/complex_class.h;
329     #endif
330 cbauer 1.1
331 cbauer 1.2 #endif // ndef __GINAC_NUMERIC_H__

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