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

Contents of /ginac/numeric.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Nov 9 19:57:04 1999 UTC (13 years, 6 months ago) by cbauer
Branch: MAIN
File MIME type: text/plain
- switched to automake build environment

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

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