3 * Makes the interface to the underlying bignum package available. */
6 * GiNaC Copyright (C) 1999-2001 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 #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; }
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>
43 #define HASHVALUE_NUMERIC 0x80000001U
45 /** This class is used to instantiate a global singleton object Digits
46 * which behaves just like Maple's Digits. We need an object rather
47 * than a dumber basic type since as a side-effect we let it change
48 * cl_default_float_format when it gets changed. The only other
49 * meaningful thing to do with it is converting it to an unsigned,
50 * for temprary storing its value e.g. The user must not create an
51 * own working object of this class! Since C++ forces us to make the
52 * class definition visible in order to use an object we put in a
53 * flag which prevents other objects of that class to be created. */
59 _numeric_digits& operator=(long prec);
61 void print(std::ostream &os) const;
64 long digits; ///< Number of decimal digits
65 static bool too_late; ///< Already one object present
68 /** This class is a wrapper around CLN-numbers within the GiNaC class
69 * hierarchy. Objects of this type may directly be created by the user.*/
70 class numeric : public basic
72 GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)
78 explicit numeric(int i);
79 explicit numeric(unsigned int i);
80 explicit numeric(long i);
81 explicit numeric(unsigned long i);
82 explicit numeric(long numer, long denom);
83 explicit numeric(double d);
84 explicit numeric(const char *);
86 // functions overriding virtual functions from bases classes
88 void print(std::ostream &os, unsigned precedence = 0) const;
89 void printraw(std::ostream &os) const;
90 void printtree(std::ostream &os, unsigned indent) const;
91 void printcsrc(std::ostream &os, unsigned type, unsigned precedence=0) const;
92 bool info(unsigned inf) const;
93 bool has(const ex &other) const;
94 ex eval(int level = 0) const;
95 ex evalf(int level = 0) const;
96 ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
97 ex to_rational(lst &repl_lst) const;
98 numeric integer_content(void) const;
99 ex smod(const numeric &xi) const;
100 numeric max_coefficient(void) const;
102 /** Implementation of ex::diff for a numeric always returns 0.
104 ex derivative(const symbol &s) const { return _ex0(); }
105 bool is_equal_same_type(const basic &other) const;
106 unsigned calchash(void) const;
108 // new virtual functions which can be overridden by derived classes
111 // non-virtual functions in this class
113 const numeric add(const numeric &other) const;
114 const numeric sub(const numeric &other) const;
115 const numeric mul(const numeric &other) const;
116 const numeric div(const numeric &other) const;
117 const numeric power(const numeric &other) const;
118 const numeric & add_dyn(const numeric &other) const;
119 const numeric & sub_dyn(const numeric &other) const;
120 const numeric & mul_dyn(const numeric &other) const;
121 const numeric & div_dyn(const numeric &other) const;
122 const numeric & power_dyn(const numeric &other) const;
123 const numeric & operator=(int i);
124 const numeric & operator=(unsigned int i);
125 const numeric & operator=(long i);
126 const numeric & operator=(unsigned long i);
127 const numeric & operator=(double d);
128 const numeric & operator=(const char *s);
129 const numeric inverse(void) const;
130 int csgn(void) const;
131 int compare(const numeric &other) const;
132 bool is_equal(const numeric &other) const;
133 bool is_zero(void) const;
134 bool is_positive(void) const;
135 bool is_negative(void) const;
136 bool is_integer(void) const;
137 bool is_pos_integer(void) const;
138 bool is_nonneg_integer(void) const;
139 bool is_even(void) const;
140 bool is_odd(void) const;
141 bool is_prime(void) const;
142 bool is_rational(void) const;
143 bool is_real(void) const;
144 bool is_cinteger(void) const;
145 bool is_crational(void) const;
146 bool operator==(const numeric &other) const;
147 bool operator!=(const numeric &other) const;
148 bool operator<(const numeric &other) const;
149 bool operator<=(const numeric &other) const;
150 bool operator>(const numeric &other) const;
151 bool operator>=(const numeric &other) const;
152 int to_int(void) const;
153 long to_long(void) const;
154 double to_double(void) const;
155 cln::cl_N to_cl_N(void) const;
156 const numeric real(void) const;
157 const numeric imag(void) const;
158 const numeric numer(void) const;
159 const numeric denom(void) const;
160 int int_length(void) const;
161 // converting routines for interfacing with CLN:
162 numeric(const cln::cl_N &z);
167 static unsigned precedence;
168 cln::cl_number value;
173 extern const numeric I;
174 extern _numeric_digits Digits;
176 // deprecated macro, for internal use only
177 #define is_a_numeric_hash(x) ((x)&0x80000000U)
181 const numeric exp(const numeric &x);
182 const numeric log(const numeric &x);
183 const numeric sin(const numeric &x);
184 const numeric cos(const numeric &x);
185 const numeric tan(const numeric &x);
186 const numeric asin(const numeric &x);
187 const numeric acos(const numeric &x);
188 const numeric atan(const numeric &x);
189 const numeric atan(const numeric &y, const numeric &x);
190 const numeric sinh(const numeric &x);
191 const numeric cosh(const numeric &x);
192 const numeric tanh(const numeric &x);
193 const numeric asinh(const numeric &x);
194 const numeric acosh(const numeric &x);
195 const numeric atanh(const numeric &x);
196 const numeric Li2(const numeric &x);
197 const numeric zeta(const numeric &x);
198 const numeric lgamma(const numeric &x);
199 const numeric tgamma(const numeric &x);
200 const numeric psi(const numeric &x);
201 const numeric psi(const numeric &n, const numeric &x);
202 const numeric factorial(const numeric &n);
203 const numeric doublefactorial(const numeric &n);
204 const numeric binomial(const numeric &n, const numeric &k);
205 const numeric bernoulli(const numeric &n);
206 const numeric fibonacci(const numeric &n);
207 const numeric abs(const numeric &x);
208 const numeric isqrt(const numeric &x);
209 const numeric sqrt(const numeric &x);
210 const numeric abs(const numeric &x);
211 const numeric mod(const numeric &a, const numeric &b);
212 const numeric smod(const numeric &a, const numeric &b);
213 const numeric irem(const numeric &a, const numeric &b);
214 const numeric irem(const numeric &a, const numeric &b, numeric &q);
215 const numeric iquo(const numeric &a, const numeric &b);
216 const numeric iquo(const numeric &a, const numeric &b, numeric &r);
217 const numeric gcd(const numeric &a, const numeric &b);
218 const numeric lcm(const numeric &a, const numeric &b);
220 // wrapper functions around member functions
221 inline const numeric pow(const numeric &x, const numeric &y)
222 { return x.power(y); }
224 inline const numeric inverse(const numeric &x)
225 { return x.inverse(); }
227 inline int csgn(const numeric &x)
230 inline bool is_zero(const numeric &x)
231 { return x.is_zero(); }
233 inline bool is_positive(const numeric &x)
234 { return x.is_positive(); }
236 inline bool is_integer(const numeric &x)
237 { return x.is_integer(); }
239 inline bool is_pos_integer(const numeric &x)
240 { return x.is_pos_integer(); }
242 inline bool is_nonneg_integer(const numeric &x)
243 { return x.is_nonneg_integer(); }
245 inline bool is_even(const numeric &x)
246 { return x.is_even(); }
248 inline bool is_odd(const numeric &x)
249 { return x.is_odd(); }
251 inline bool is_prime(const numeric &x)
252 { return x.is_prime(); }
254 inline bool is_rational(const numeric &x)
255 { return x.is_rational(); }
257 inline bool is_real(const numeric &x)
258 { return x.is_real(); }
260 inline bool is_cinteger(const numeric &x)
261 { return x.is_cinteger(); }
263 inline bool is_crational(const numeric &x)
264 { return x.is_crational(); }
266 inline int to_int(const numeric &x)
267 { return x.to_int(); }
269 inline long to_long(const numeric &x)
270 { return x.to_long(); }
272 inline double to_double(const numeric &x)
273 { return x.to_double(); }
275 inline const numeric real(const numeric &x)
278 inline const numeric imag(const numeric &x)
281 inline const numeric numer(const numeric &x)
282 { return x.numer(); }
284 inline const numeric denom(const numeric &x)
285 { return x.denom(); }
287 // numeric evaluation functions for class constant objects:
291 ex CatalanEvalf(void);
295 inline const numeric &ex_to_numeric(const ex &e)
297 return static_cast<const numeric &>(*e.bp);
303 #pragma link off defined_in cln/number.h;
304 #pragma link off defined_in cln/complex_class.h;
307 #endif // ndef __GINAC_NUMERIC_H__