3 * Makes the interface to the underlying bignum package available. */
6 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
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.
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.
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
23 #ifndef __GINAC_NUMERIC_H__
24 #define __GINAC_NUMERIC_H__
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.
33 #ifndef NO_NAMESPACE_GINAC
35 #endif // ndef NO_NAMESPACE_GINAC
37 #define HASHVALUE_NUMERIC 0x80000001U
39 /** This class is used to instantiate a global object Digits which
40 * behaves just like Maple's Digits. We need an object rather than a
41 * dumber basic type since as a side-effect we let it change
42 * cl_default_float_format when it gets changed. The only other
43 * meaningful thing to do with it is converting it to an unsigned,
44 * for temprary storing its value e.g. The user must not create an
45 * own working object of this class! Since C++ forces us to make the
46 * class definition visible in order to use an object we put in a
47 * flag which prevents other objects of that class to be created. */
53 _numeric_digits& operator=(long prec);
55 void print(ostream & os) const;
62 /** This class is a wrapper around CLN-numbers within the GiNaC class
63 * hierarchy. Objects of this type may directly be created by the user.*/
64 class numeric : public basic
66 GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)
69 friend const numeric exp(const numeric & x);
70 friend const numeric log(const numeric & x);
71 friend const numeric sin(const numeric & x);
72 friend const numeric cos(const numeric & x);
73 friend const numeric tan(const numeric & x);
74 friend const numeric asin(const numeric & x);
75 friend const numeric acos(const numeric & x);
76 friend const numeric atan(const numeric & x);
77 friend const numeric atan(const numeric & y, const numeric & x);
78 friend const numeric sinh(const numeric & x);
79 friend const numeric cosh(const numeric & x);
80 friend const numeric tanh(const numeric & x);
81 friend const numeric asinh(const numeric & x);
82 friend const numeric acosh(const numeric & x);
83 friend const numeric atanh(const numeric & x);
84 friend const numeric zeta(const numeric & x);
85 friend const numeric bernoulli(const numeric & n);
86 friend numeric abs(const numeric & x);
87 friend numeric mod(const numeric & a, const numeric & b);
88 friend numeric smod(const numeric & a, const numeric & b);
89 friend numeric irem(const numeric & a, const numeric & b);
90 friend numeric irem(const numeric & a, const numeric & b, numeric & q);
91 friend numeric iquo(const numeric & a, const numeric & b);
92 friend numeric iquo(const numeric & a, const numeric & b, numeric & r);
93 friend numeric sqrt(const numeric & x);
94 friend numeric isqrt(const numeric & x);
95 friend numeric gcd(const numeric & a, const numeric & b);
96 friend numeric lcm(const numeric & a, const numeric & b);
100 // default constructor, destructor, copy constructor assignment
101 // operator and helpers
105 numeric(const numeric & other);
106 const numeric & operator=(const numeric & other);
108 void copy(const numeric & other);
109 void destroy(bool call_parent);
111 // other constructors
113 explicit numeric(int i);
114 explicit numeric(unsigned int i);
115 explicit numeric(long i);
116 explicit numeric(unsigned long i);
117 explicit numeric(long numer, long denom);
118 explicit numeric(double d);
119 explicit numeric(const char *);
120 numeric(const cl_N & z);
122 // functions overriding virtual functions from bases classes
124 basic * duplicate() const;
125 void print(ostream & os, unsigned precedence=0) const;
126 void printraw(ostream & os) const;
127 void printtree(ostream & os, unsigned indent) const;
128 void printcsrc(ostream & os, unsigned type, unsigned precedence=0) const;
129 bool info(unsigned inf) const;
130 bool has(const ex & other) const;
131 ex eval(int level=0) const;
132 ex evalf(int level=0) const;
133 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
134 numeric integer_content(void) const;
135 ex smod(const numeric &xi) const;
136 numeric max_coefficient(void) const;
138 ex derivative(const symbol & s) const;
139 int compare_same_type(const basic & other) const;
140 bool is_equal_same_type(const basic & other) const;
141 unsigned calchash(void) const {
142 hashvalue=HASHVALUE_NUMERIC;
143 return HASHVALUE_NUMERIC;
146 // new virtual functions which can be overridden by derived classes
149 // non-virtual functions in this class
151 numeric add(const numeric & other) const;
152 numeric sub(const numeric & other) const;
153 numeric mul(const numeric & other) const;
154 numeric div(const numeric & other) const;
155 numeric power(const numeric & other) const;
156 const numeric & add_dyn(const numeric & other) const;
157 const numeric & sub_dyn(const numeric & other) const;
158 const numeric & mul_dyn(const numeric & other) const;
159 const numeric & div_dyn(const numeric & other) const;
160 const numeric & power_dyn(const numeric & other) const;
161 const numeric & operator=(int i);
162 const numeric & operator=(unsigned int i);
163 const numeric & operator=(long i);
164 const numeric & operator=(unsigned long i);
165 const numeric & operator=(double d);
166 const numeric & operator=(const char * s);
167 numeric inverse(void) const;
168 int csgn(void) const;
169 int compare(const numeric & other) const;
170 bool is_equal(const numeric & other) const;
171 bool is_zero(void) const;
172 bool is_positive(void) const;
173 bool is_negative(void) const;
174 bool is_integer(void) const;
175 bool is_pos_integer(void) const;
176 bool is_nonneg_integer(void) const;
177 bool is_even(void) const;
178 bool is_odd(void) const;
179 bool is_prime(void) const;
180 bool is_rational(void) const;
181 bool is_real(void) const;
182 bool is_cinteger(void) const;
183 bool is_crational(void) const;
184 bool operator==(const numeric & other) const;
185 bool operator!=(const numeric & other) const;
186 bool operator<(const numeric & other) const;
187 bool operator<=(const numeric & other) const;
188 bool operator>(const numeric & other) const;
189 bool operator>=(const numeric & other) const;
190 int to_int(void) const;
191 long to_long(void) const;
192 double to_double(void) const;
193 numeric real(void) const;
194 numeric imag(void) const;
195 numeric numer(void) const;
196 numeric denom(void) const;
197 int int_length(void) const;
202 static unsigned precedence;
208 extern const numeric some_numeric;
209 extern const numeric I;
210 extern const type_info & typeid_numeric;
211 extern _numeric_digits Digits;
213 #define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)
214 // may have to be changed to ((x)>=0x80000000U)
218 const numeric exp(const numeric & x);
219 const numeric log(const numeric & x);
220 const numeric sin(const numeric & x);
221 const numeric cos(const numeric & x);
222 const numeric tan(const numeric & x);
223 const numeric asin(const numeric & x);
224 const numeric acos(const numeric & x);
225 const numeric atan(const numeric & x);
226 const numeric atan(const numeric & y, const numeric & x);
227 const numeric sinh(const numeric & x);
228 const numeric cosh(const numeric & x);
229 const numeric tanh(const numeric & x);
230 const numeric asinh(const numeric & x);
231 const numeric acosh(const numeric & x);
232 const numeric atanh(const numeric & x);
233 const numeric zeta(const numeric & x);
234 const numeric gamma(const numeric & x);
235 const numeric psi(const numeric & x);
236 const numeric psi(const numeric & n, const numeric & x);
237 const numeric factorial(const numeric & n);
238 const numeric doublefactorial(const numeric & n);
239 const numeric binomial(const numeric & n, const numeric & k);
240 const numeric bernoulli(const numeric & n);
241 const numeric fibonacci(const numeric & n);
243 numeric abs(const numeric & x);
244 numeric mod(const numeric & a, const numeric & b);
245 numeric smod(const numeric & a, const numeric & b);
246 numeric irem(const numeric & a, const numeric & b);
247 numeric irem(const numeric & a, const numeric & b, numeric & q);
248 numeric iquo(const numeric & a, const numeric & b);
249 numeric iquo(const numeric & a, const numeric & b, numeric & r);
250 numeric sqrt(const numeric & x);
251 numeric isqrt(const numeric & x);
253 numeric gcd(const numeric & a, const numeric & b);
254 numeric lcm(const numeric & a, const numeric & b);
256 /** Exception thrown by numeric members to signal failure */
260 numeric_fail(int n) { failval = n; }
263 // wrapper functions around member functions
264 inline numeric pow(const numeric & x, const numeric & y)
265 { return x.power(y); }
267 inline numeric inverse(const numeric & x)
268 { return x.inverse(); }
270 inline bool csgn(const numeric & x)
273 inline bool is_zero(const numeric & x)
274 { return x.is_zero(); }
276 inline bool is_positive(const numeric & x)
277 { return x.is_positive(); }
279 inline bool is_integer(const numeric & x)
280 { return x.is_integer(); }
282 inline bool is_pos_integer(const numeric & x)
283 { return x.is_pos_integer(); }
285 inline bool is_nonneg_integer(const numeric & x)
286 { return x.is_nonneg_integer(); }
288 inline bool is_even(const numeric & x)
289 { return x.is_even(); }
291 inline bool is_odd(const numeric & x)
292 { return x.is_odd(); }
294 inline bool is_prime(const numeric & x)
295 { return x.is_prime(); }
297 inline bool is_rational(const numeric & x)
298 { return x.is_rational(); }
300 inline bool is_real(const numeric & x)
301 { return x.is_real(); }
303 inline bool is_cinteger(const numeric & x)
304 { return x.is_cinteger(); }
306 inline bool is_crational(const numeric & x)
307 { return x.is_crational(); }
309 inline numeric real(const numeric & x)
312 inline numeric imag(const numeric & x)
315 inline numeric numer(const numeric & x)
316 { return x.numer(); }
318 inline numeric denom(const numeric & x)
319 { return x.denom(); }
321 // numeric evaluation functions for class constant objects:
324 ex EulerGammaEvalf(void);
325 ex CatalanEvalf(void);
329 inline const numeric &ex_to_numeric(const ex &e)
331 return static_cast<const numeric &>(*e.bp);
335 #ifndef NO_NAMESPACE_GINAC
337 #endif // ndef NO_NAMESPACE_GINAC
339 #endif // ndef __GINAC_NUMERIC_H__