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

Contents of /ginac/numeric.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations)
Wed Dec 1 18:13:01 1999 UTC (13 years, 5 months ago) by kreckel
Branch: MAIN
Changes since 1.10: +2 -1 lines
File MIME type: text/plain
- added prefix and postfix increment and decrement operators for class numeric
- made all function_index const
- added overloaded psi(x) and psi(n,x) with some sensible behaviour

1 cbauer 1.1 /** @file numeric.h
2     *
3 cbauer 1.4 * Makes the interface to the underlying bignum package available. */
4    
5     /*
6 cbauer 1.2 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
7     *
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.3 #include <ginac/basic.h>
28 cbauer 1.5 #include <ginac/ex.h>
29 cbauer 1.1
30     class cl_N; // We want to include cln.h only in numeric.cpp in order to
31     // avoid namespace pollution and keep compile-time low.
32    
33 cbauer 1.5 namespace GiNaC {
34    
35     #define HASHVALUE_NUMERIC 0x80000001U
36    
37 cbauer 1.1 /** This class is used to instantiate a global object Digits which
38     * behaves just like Maple's Digits. We need an object rather than a
39     * dumber basic type since as a side-effect we let it change
40     * cl_default_float_format when it gets changed. The only other
41     * meaningful thing to do with it is converting it to an unsigned,
42     * for temprary storing its value e.g. The user must not create an
43     * own working object of this class! Since C++ forces us to make the
44     * class definition visible in order to use an object we put in a
45     * flag which prevents other objects of that class to be created. */
46     class _numeric_digits
47     {
48     // member functions
49     public:
50     _numeric_digits();
51     _numeric_digits& operator=(long prec);
52     operator long();
53     void print(ostream & os) const;
54     // member variables
55     private:
56     long digits;
57     static bool too_late;
58     };
59    
60     /** This class is a wrapper around CLN-numbers within the GiNaC class
61     * hierarchy. Objects of this type may directly be created by the user.*/
62     class numeric : public basic
63     {
64     // friends
65     friend numeric exp(numeric const & x);
66     friend numeric log(numeric const & x);
67     friend numeric sin(numeric const & x);
68     friend numeric cos(numeric const & x);
69     friend numeric tan(numeric const & x);
70     friend numeric asin(numeric const & x);
71     friend numeric acos(numeric const & x);
72     friend numeric atan(numeric const & x);
73     friend numeric atan(numeric const & y, numeric const & x);
74     friend numeric sinh(numeric const & x);
75     friend numeric cosh(numeric const & x);
76     friend numeric tanh(numeric const & x);
77     friend numeric asinh(numeric const & x);
78     friend numeric acosh(numeric const & x);
79     friend numeric atanh(numeric const & x);
80 kreckel 1.8 friend numeric bernoulli(numeric const & n);
81 cbauer 1.1 friend numeric abs(numeric const & x);
82     friend numeric mod(numeric const & a, numeric const & b);
83     friend numeric smod(numeric const & a, numeric const & b);
84     friend numeric irem(numeric const & a, numeric const & b);
85     friend numeric irem(numeric const & a, numeric const & b, numeric & q);
86     friend numeric iquo(numeric const & a, numeric const & b);
87     friend numeric iquo(numeric const & a, numeric const & b, numeric & r);
88     friend numeric sqrt(numeric const & x);
89     friend numeric isqrt(numeric const & x);
90     friend numeric gcd(numeric const & a, numeric const & b);
91     friend numeric lcm(numeric const & a, numeric const & b);
92     friend numeric const & numZERO(void);
93     friend numeric const & numONE(void);
94     friend numeric const & numTWO(void);
95     friend numeric const & numTHREE(void);
96     friend numeric const & numMINUSONE(void);
97     friend numeric const & numHALF(void);
98    
99     // member functions
100    
101     // default constructor, destructor, copy constructor assignment
102     // operator and helpers
103     public:
104     numeric();
105     ~numeric();
106     numeric(numeric const & other);
107     numeric const & operator=(numeric const & other);
108     protected:
109     void copy(numeric const & other);
110     void destroy(bool call_parent);
111    
112     // other constructors
113     public:
114     explicit numeric(int i);
115     explicit numeric(unsigned int i);
116     explicit numeric(long i);
117     explicit numeric(unsigned long i);
118     explicit numeric(long numer, long denom);
119     explicit numeric(double d);
120     explicit numeric(char const *);
121     numeric(cl_N const & z);
122    
123     // functions overriding virtual functions from bases classes
124     public:
125     basic * duplicate() const;
126     void printraw(ostream & os) const;
127     void printtree(ostream & os, unsigned indent) const;
128     void print(ostream & os, unsigned precedence=0) const;
129     void printcsrc(ostream & os, unsigned type, unsigned precedence=0) const;
130     bool info(unsigned inf) const;
131     ex evalf(int level=0) const;
132     ex diff(symbol const & s) const;
133     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
134     numeric integer_content(void) const;
135     ex smod(numeric const &xi) const;
136     numeric max_coefficient(void) const;
137     protected:
138     int compare_same_type(basic const & other) const;
139     bool is_equal_same_type(basic const & other) const;
140     unsigned calchash(void) const {
141     hashvalue=HASHVALUE_NUMERIC;
142     return HASHVALUE_NUMERIC;
143     }
144    
145     // new virtual functions which can be overridden by derived classes
146     // (none)
147    
148     // non-virtual functions in this class
149     public:
150     numeric add(numeric const & other) const;
151     numeric sub(numeric const & other) const;
152     numeric mul(numeric const & other) const;
153     numeric div(numeric const & other) const;
154     numeric power(numeric const & other) const;
155     numeric const & add_dyn(numeric const & other) const;
156     numeric const & sub_dyn(numeric const & other) const;
157     numeric const & mul_dyn(numeric const & other) const;
158     numeric const & div_dyn(numeric const & other) const;
159     numeric const & power_dyn(numeric const & other) const;
160     numeric const & operator=(int i);
161     numeric const & operator=(unsigned int i);
162     numeric const & operator=(long i);
163     numeric const & operator=(unsigned long i);
164     numeric const & operator=(double d);
165     numeric const & operator=(char const * s);
166     /*
167     numeric add_dyn(numeric const & other) const { return add(other); }
168     numeric sub_dyn(numeric const & other) const { return sub(other); }
169     numeric mul_dyn(numeric const & other) const { return mul(other); }
170     numeric div_dyn(numeric const & other) const { return div(other); }
171     numeric power_dyn(numeric const & other) const { return power(other); }
172     */
173     numeric inverse(void) const;
174 kreckel 1.6 int csgn(void) const;
175 cbauer 1.1 int compare(numeric const & other) const;
176     bool is_equal(numeric const & other) const;
177     bool is_zero(void) const;
178     bool is_positive(void) const;
179     bool is_negative(void) const;
180     bool is_integer(void) const;
181     bool is_pos_integer(void) const;
182     bool is_nonneg_integer(void) const;
183     bool is_even(void) const;
184     bool is_odd(void) const;
185     bool is_prime(void) const;
186     bool is_rational(void) const;
187     bool is_real(void) const;
188     bool operator==(numeric const & other) const;
189     bool operator!=(numeric const & other) const;
190     bool operator<(numeric const & other) const;
191     bool operator<=(numeric const & other) const;
192     bool operator>(numeric const & other) const;
193     bool operator>=(numeric const & other) const;
194     int to_int(void) const;
195     double to_double(void) const;
196     numeric real(void) const;
197     numeric imag(void) const;
198     numeric numer(void) const;
199     numeric denom(void) const;
200     int int_length(void) const;
201    
202     // member variables
203    
204     protected:
205     static unsigned precedence;
206     cl_N *value;
207     };
208    
209     // global constants
210    
211     extern const numeric some_numeric;
212     extern const numeric I;
213     extern type_info const & typeid_numeric;
214     extern _numeric_digits Digits;
215    
216     #define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)
217     // may have to be changed to ((x)>=0x80000000U)
218    
219     // global functions
220    
221     numeric const & numZERO(void);
222     numeric const & numONE(void);
223     numeric const & numTWO(void);
224     numeric const & numMINUSONE(void);
225     numeric const & numHALF(void);
226    
227     numeric exp(numeric const & x);
228     numeric log(numeric const & x);
229     numeric sin(numeric const & x);
230     numeric cos(numeric const & x);
231     numeric tan(numeric const & x);
232     numeric asin(numeric const & x);
233     numeric acos(numeric const & x);
234     numeric atan(numeric const & x);
235     numeric atan(numeric const & y, numeric const & x);
236     numeric sinh(numeric const & x);
237     numeric cosh(numeric const & x);
238     numeric tanh(numeric const & x);
239     numeric asinh(numeric const & x);
240     numeric acosh(numeric const & x);
241     numeric atanh(numeric const & x);
242 kreckel 1.7 numeric zeta(numeric const & x);
243 cbauer 1.1 numeric gamma(numeric const & x);
244 kreckel 1.10 numeric psi(numeric const & x);
245 kreckel 1.7 numeric psi(numeric const & n, numeric const & x);
246 cbauer 1.1 numeric factorial(numeric const & n);
247     numeric doublefactorial(numeric const & n);
248     numeric binomial(numeric const & n, numeric const & k);
249 kreckel 1.8 numeric bernoulli(numeric const & n);
250 cbauer 1.1
251     numeric abs(numeric const & x);
252     numeric mod(numeric const & a, numeric const & b);
253     numeric smod(numeric const & a, numeric const & b);
254     numeric irem(numeric const & a, numeric const & b);
255     numeric irem(numeric const & a, numeric const & b, numeric & q);
256     numeric iquo(numeric const & a, numeric const & b);
257     numeric iquo(numeric const & a, numeric const & b, numeric & r);
258     numeric sqrt(numeric const & x);
259     numeric isqrt(numeric const & x);
260    
261     numeric gcd(numeric const & a, numeric const & b);
262     numeric lcm(numeric const & a, numeric const & b);
263    
264     /** Exception thrown by numeric members to signal failure */
265     struct numeric_fail
266     {
267     int failval;
268     numeric_fail(int n) { failval = n; }
269     };
270    
271     // wrapper functions around member functions
272     inline numeric inverse(numeric const & x)
273     { return x.inverse(); }
274 kreckel 1.6
275     inline bool csgn(numeric const & x)
276     { return x.csgn(); }
277 cbauer 1.1
278     inline bool is_zero(numeric const & x)
279     { return x.is_zero(); }
280    
281     inline bool is_positive(numeric const & x)
282     { return x.is_positive(); }
283    
284     inline bool is_integer(numeric const & x)
285     { return x.is_integer(); }
286    
287     inline bool is_pos_integer(numeric const & x)
288     { return x.is_pos_integer(); }
289    
290     inline bool is_nonneg_integer(numeric const & x)
291     { return x.is_nonneg_integer(); }
292    
293     inline bool is_even(numeric const & x)
294     { return x.is_even(); }
295    
296     inline bool is_odd(numeric const & x)
297     { return x.is_odd(); }
298    
299     inline bool is_prime(numeric const & x)
300     { return x.is_prime(); }
301    
302     inline bool is_rational(numeric const & x)
303     { return x.is_rational(); }
304    
305     inline bool is_real(numeric const & x)
306     { return x.is_real(); }
307    
308     inline numeric real(numeric const & x)
309     { return x.real(); }
310    
311     inline numeric imag(numeric const & x)
312     { return x.imag(); }
313    
314     inline numeric numer(numeric const & x)
315     { return x.numer(); }
316    
317     inline numeric denom(numeric const & x)
318     { return x.denom(); }
319    
320 kreckel 1.11 // numeric evaluation functions for class constant objects:
321    
322 cbauer 1.1 ex PiEvalf(void);
323     ex EulerGammaEvalf(void);
324     ex CatalanEvalf(void);
325    
326 cbauer 1.5 // utility functions
327     inline const numeric &ex_to_numeric(const ex &e)
328     {
329     return static_cast<const numeric &>(*e.bp);
330     }
331 cbauer 1.1
332 cbauer 1.5 } // namespace GiNaC
333 cbauer 1.1
334 cbauer 1.2 #endif // ndef __GINAC_NUMERIC_H__

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