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

Contents of /ginac/numeric.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.52 - (hide annotations)
Tue Jun 5 09:55:06 2001 UTC (12 years ago) by kreckel
Branch: MAIN
CVS Tags: release_0-9-0
Changes since 1.51: +0 -1 lines
File MIME type: text/plain
- ++version_major.
- added matrix::pow() to handle integer exponents with the least amount of
  multiplications possible and...
- ...added power::evalm() to actually use it.
- classhierarchy.fig: add class wildcard.
- some cleanups.

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 cbauer 1.21 #include "basic.h"
27     #include "ex.h"
28 cbauer 1.1
29 kreckel 1.41 #include <cln/number.h>
30     // forward decln of cln::cl_N, since cln/complex_class.h is not included:
31     namespace cln { class cl_N; }
32    
33     #if defined(G__CINTVERSION) && !defined(__MAKECINT__)
34     // Cint @$#$! doesn't like forward declaring classes used for casting operators
35     // so we have to include the definition of cln::cl_N here, but it is enough to
36     // do so for the compiler, hence the !defined(__MAKECINT__).
37     #include <cln/complex_class.h>
38     #endif
39 cbauer 1.1
40 cbauer 1.5 namespace GiNaC {
41    
42     #define HASHVALUE_NUMERIC 0x80000001U
43    
44 kreckel 1.48 /** This class is used to instantiate a global singleton object Digits
45     * which behaves just like Maple's Digits. We need an object rather
46     * than a dumber basic type since as a side-effect we let it change
47 cbauer 1.1 * cl_default_float_format when it gets changed. The only other
48     * meaningful thing to do with it is converting it to an unsigned,
49     * for temprary storing its value e.g. The user must not create an
50     * own working object of this class! Since C++ forces us to make the
51     * class definition visible in order to use an object we put in a
52     * flag which prevents other objects of that class to be created. */
53     class _numeric_digits
54     {
55     // member functions
56     public:
57 cbauer 1.38 _numeric_digits();
58     _numeric_digits& operator=(long prec);
59     operator long();
60 kreckel 1.48 void print(std::ostream &os) const;
61 cbauer 1.1 // member variables
62     private:
63 kreckel 1.48 long digits; ///< Number of decimal digits
64     static bool too_late; ///< Already one object present
65 cbauer 1.1 };
66    
67     /** This class is a wrapper around CLN-numbers within the GiNaC class
68     * hierarchy. Objects of this type may directly be created by the user.*/
69     class numeric : public basic
70     {
71 cbauer 1.38 GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)
72 kreckel 1.48
73 cbauer 1.1 // member functions
74 kreckel 1.48
75     // other ctors
76 cbauer 1.1 public:
77 cbauer 1.38 explicit numeric(int i);
78     explicit numeric(unsigned int i);
79     explicit numeric(long i);
80     explicit numeric(unsigned long i);
81     explicit numeric(long numer, long denom);
82     explicit numeric(double d);
83     explicit numeric(const char *);
84    
85     // functions overriding virtual functions from bases classes
86 cbauer 1.1 public:
87 cbauer 1.49 void print(const print_context & c, unsigned level = 0) const;
88 cbauer 1.51 unsigned precedence(void) const {return 30;}
89 cbauer 1.38 bool info(unsigned inf) const;
90 kreckel 1.48 bool has(const ex &other) const;
91 kreckel 1.47 ex eval(int level = 0) const;
92     ex evalf(int level = 0) const;
93 kreckel 1.48 ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
94 cbauer 1.38 ex to_rational(lst &repl_lst) const;
95     numeric integer_content(void) const;
96     ex smod(const numeric &xi) const;
97     numeric max_coefficient(void) const;
98 cbauer 1.1 protected:
99 kreckel 1.48 /** Implementation of ex::diff for a numeric always returns 0.
100     * @see ex::diff */
101     ex derivative(const symbol &s) const { return _ex0(); }
102     bool is_equal_same_type(const basic &other) const;
103 cbauer 1.38 unsigned calchash(void) const;
104 kreckel 1.48
105 cbauer 1.38 // new virtual functions which can be overridden by derived classes
106     // (none)
107 kreckel 1.48
108 cbauer 1.38 // non-virtual functions in this class
109 cbauer 1.1 public:
110 kreckel 1.48 const numeric add(const numeric &other) const;
111     const numeric sub(const numeric &other) const;
112     const numeric mul(const numeric &other) const;
113     const numeric div(const numeric &other) const;
114     const numeric power(const numeric &other) const;
115     const numeric & add_dyn(const numeric &other) const;
116     const numeric & sub_dyn(const numeric &other) const;
117     const numeric & mul_dyn(const numeric &other) const;
118     const numeric & div_dyn(const numeric &other) const;
119     const numeric & power_dyn(const numeric &other) const;
120 cbauer 1.38 const numeric & operator=(int i);
121     const numeric & operator=(unsigned int i);
122     const numeric & operator=(long i);
123     const numeric & operator=(unsigned long i);
124     const numeric & operator=(double d);
125 kreckel 1.48 const numeric & operator=(const char *s);
126 kreckel 1.41 const numeric inverse(void) const;
127 cbauer 1.38 int csgn(void) const;
128 kreckel 1.48 int compare(const numeric &other) const;
129     bool is_equal(const numeric &other) const;
130 cbauer 1.38 bool is_zero(void) const;
131     bool is_positive(void) const;
132     bool is_negative(void) const;
133     bool is_integer(void) const;
134     bool is_pos_integer(void) const;
135     bool is_nonneg_integer(void) const;
136     bool is_even(void) const;
137     bool is_odd(void) const;
138     bool is_prime(void) const;
139     bool is_rational(void) const;
140     bool is_real(void) const;
141     bool is_cinteger(void) const;
142     bool is_crational(void) const;
143 kreckel 1.48 bool operator==(const numeric &other) const;
144     bool operator!=(const numeric &other) const;
145     bool operator<(const numeric &other) const;
146     bool operator<=(const numeric &other) const;
147     bool operator>(const numeric &other) const;
148     bool operator>=(const numeric &other) const;
149 cbauer 1.38 int to_int(void) const;
150     long to_long(void) const;
151     double to_double(void) const;
152 kreckel 1.42 cln::cl_N to_cl_N(void) const;
153 cbauer 1.38 const numeric real(void) const;
154     const numeric imag(void) const;
155     const numeric numer(void) const;
156     const numeric denom(void) const;
157     int int_length(void) const;
158 kreckel 1.41 // converting routines for interfacing with CLN:
159 kreckel 1.48 numeric(const cln::cl_N &z);
160 cbauer 1.1
161     // member variables
162    
163     protected:
164 kreckel 1.41 cln::cl_number value;
165 cbauer 1.1 };
166    
167     // global constants
168    
169     extern const numeric I;
170     extern _numeric_digits Digits;
171    
172 kreckel 1.48 // deprecated macro, for internal use only
173     #define is_a_numeric_hash(x) ((x)&0x80000000U)
174 cbauer 1.1
175     // global functions
176    
177 kreckel 1.48 const numeric exp(const numeric &x);
178     const numeric log(const numeric &x);
179     const numeric sin(const numeric &x);
180     const numeric cos(const numeric &x);
181     const numeric tan(const numeric &x);
182     const numeric asin(const numeric &x);
183     const numeric acos(const numeric &x);
184     const numeric atan(const numeric &x);
185     const numeric atan(const numeric &y, const numeric &x);
186     const numeric sinh(const numeric &x);
187     const numeric cosh(const numeric &x);
188     const numeric tanh(const numeric &x);
189     const numeric asinh(const numeric &x);
190     const numeric acosh(const numeric &x);
191     const numeric atanh(const numeric &x);
192     const numeric Li2(const numeric &x);
193     const numeric zeta(const numeric &x);
194     const numeric lgamma(const numeric &x);
195     const numeric tgamma(const numeric &x);
196     const numeric psi(const numeric &x);
197     const numeric psi(const numeric &n, const numeric &x);
198     const numeric factorial(const numeric &n);
199     const numeric doublefactorial(const numeric &n);
200     const numeric binomial(const numeric &n, const numeric &k);
201     const numeric bernoulli(const numeric &n);
202     const numeric fibonacci(const numeric &n);
203     const numeric isqrt(const numeric &x);
204     const numeric sqrt(const numeric &x);
205     const numeric abs(const numeric &x);
206     const numeric mod(const numeric &a, const numeric &b);
207     const numeric smod(const numeric &a, const numeric &b);
208     const numeric irem(const numeric &a, const numeric &b);
209     const numeric irem(const numeric &a, const numeric &b, numeric &q);
210     const numeric iquo(const numeric &a, const numeric &b);
211     const numeric iquo(const numeric &a, const numeric &b, numeric &r);
212     const numeric gcd(const numeric &a, const numeric &b);
213     const numeric lcm(const numeric &a, const numeric &b);
214 cbauer 1.1
215     // wrapper functions around member functions
216 kreckel 1.48 inline const numeric pow(const numeric &x, const numeric &y)
217 kreckel 1.16 { return x.power(y); }
218    
219 kreckel 1.48 inline const numeric inverse(const numeric &x)
220 cbauer 1.1 { return x.inverse(); }
221 kreckel 1.6
222 kreckel 1.48 inline int csgn(const numeric &x)
223 kreckel 1.6 { return x.csgn(); }
224 cbauer 1.1
225 kreckel 1.48 inline bool is_zero(const numeric &x)
226 cbauer 1.1 { return x.is_zero(); }
227    
228 kreckel 1.48 inline bool is_positive(const numeric &x)
229 cbauer 1.1 { return x.is_positive(); }
230    
231 kreckel 1.48 inline bool is_integer(const numeric &x)
232 cbauer 1.1 { return x.is_integer(); }
233    
234 kreckel 1.48 inline bool is_pos_integer(const numeric &x)
235 cbauer 1.1 { return x.is_pos_integer(); }
236    
237 kreckel 1.48 inline bool is_nonneg_integer(const numeric &x)
238 cbauer 1.1 { return x.is_nonneg_integer(); }
239    
240 kreckel 1.48 inline bool is_even(const numeric &x)
241 cbauer 1.1 { return x.is_even(); }
242    
243 kreckel 1.48 inline bool is_odd(const numeric &x)
244 cbauer 1.1 { return x.is_odd(); }
245    
246 kreckel 1.48 inline bool is_prime(const numeric &x)
247 cbauer 1.1 { return x.is_prime(); }
248    
249 kreckel 1.48 inline bool is_rational(const numeric &x)
250 cbauer 1.1 { return x.is_rational(); }
251    
252 kreckel 1.48 inline bool is_real(const numeric &x)
253 cbauer 1.1 { return x.is_real(); }
254    
255 kreckel 1.48 inline bool is_cinteger(const numeric &x)
256 kreckel 1.14 { return x.is_cinteger(); }
257    
258 kreckel 1.48 inline bool is_crational(const numeric &x)
259 kreckel 1.14 { return x.is_crational(); }
260 kreckel 1.42
261 kreckel 1.48 inline int to_int(const numeric &x)
262 kreckel 1.42 { return x.to_int(); }
263    
264 kreckel 1.48 inline long to_long(const numeric &x)
265 kreckel 1.42 { return x.to_long(); }
266    
267 kreckel 1.48 inline double to_double(const numeric &x)
268 kreckel 1.42 { return x.to_double(); }
269 kreckel 1.14
270 kreckel 1.48 inline const numeric real(const numeric &x)
271 cbauer 1.1 { return x.real(); }
272    
273 kreckel 1.48 inline const numeric imag(const numeric &x)
274 cbauer 1.1 { return x.imag(); }
275    
276 kreckel 1.48 inline const numeric numer(const numeric &x)
277 cbauer 1.1 { return x.numer(); }
278    
279 kreckel 1.48 inline const numeric denom(const numeric &x)
280 cbauer 1.1 { return x.denom(); }
281    
282 kreckel 1.11 // numeric evaluation functions for class constant objects:
283    
284 cbauer 1.1 ex PiEvalf(void);
285 kreckel 1.31 ex EulerEvalf(void);
286 cbauer 1.1 ex CatalanEvalf(void);
287    
288 kreckel 1.23
289 cbauer 1.5 // utility functions
290 kreckel 1.23 inline const numeric &ex_to_numeric(const ex &e)
291     {
292 cbauer 1.38 return static_cast<const numeric &>(*e.bp);
293 kreckel 1.23 }
294    
295 cbauer 1.5 } // namespace GiNaC
296 kreckel 1.41
297     #ifdef __MAKECINT__
298     #pragma link off defined_in cln/number.h;
299     #pragma link off defined_in cln/complex_class.h;
300     #endif
301 cbauer 1.1
302 cbauer 1.2 #endif // ndef __GINAC_NUMERIC_H__

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