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

Contents of /ginac/numeric.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations)
Wed Jan 19 19:46:57 2000 UTC (13 years, 4 months ago) by cbauer
Branch: MAIN
Changes since 1.17: +2 -0 lines
File MIME type: text/plain
- implemented global class registry (for class basic and derived classes)
- implemented archiving of expressions (except for class idx, and all classes
  derived from idx and indexed)
- added series() wrapper function
- class series renamed to pseries to avoid name clashes with global series()
  wrapper function, ex::series(), and basic::series()
- corrected the series expansion of single symbols with respect to the order
  term
- calling subs() on a series didn't work

1 /** @file numeric.h
2 *
3 * Makes the interface to the underlying bignum package available. */
4
5 /*
6 * GiNaC Copyright (C) 1999-2000 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
23 #ifndef __GINAC_NUMERIC_H__
24 #define __GINAC_NUMERIC_H__
25
26 #include <strstream>
27 #include <ginac/basic.h>
28 #include <ginac/ex.h>
29
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 #ifndef NO_GINAC_NAMESPACE
34 namespace GiNaC {
35 #endif // ndef NO_GINAC_NAMESPACE
36
37 #define HASHVALUE_NUMERIC 0x80000001U
38
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. */
48 class _numeric_digits
49 {
50 // member functions
51 public:
52 _numeric_digits();
53 _numeric_digits& operator=(long prec);
54 operator long();
55 void print(ostream & os) const;
56 // member variables
57 private:
58 long digits;
59 static bool too_late;
60 };
61
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
65 {
66 GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)
67
68 // friends
69 friend numeric exp(const numeric & x);
70 friend numeric log(const numeric & x);
71 friend numeric sin(const numeric & x);
72 friend numeric cos(const numeric & x);
73 friend numeric tan(const numeric & x);
74 friend numeric asin(const numeric & x);
75 friend numeric acos(const numeric & x);
76 friend numeric atan(const numeric & x);
77 friend numeric atan(const numeric & y, const numeric & x);
78 friend numeric sinh(const numeric & x);
79 friend numeric cosh(const numeric & x);
80 friend numeric tanh(const numeric & x);
81 friend numeric asinh(const numeric & x);
82 friend numeric acosh(const numeric & x);
83 friend numeric atanh(const numeric & x);
84 friend numeric zeta(const numeric & x);
85 friend 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);
97
98 // member functions
99
100 // default constructor, destructor, copy constructor assignment
101 // operator and helpers
102 public:
103 numeric();
104 ~numeric();
105 numeric(const numeric & other);
106 const numeric & operator=(const numeric & other);
107 protected:
108 void copy(const numeric & other);
109 void destroy(bool call_parent);
110
111 // other constructors
112 public:
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(char const *);
120 numeric(cl_N const & z);
121
122 // functions overriding virtual functions from bases classes
123 public:
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 ex evalf(int level=0) const;
131 ex diff(symbol const & s) const;
132 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
133 numeric integer_content(void) const;
134 ex smod(const numeric &xi) const;
135 numeric max_coefficient(void) const;
136 protected:
137 int compare_same_type(basic const & other) const;
138 bool is_equal_same_type(basic const & other) const;
139 unsigned calchash(void) const {
140 hashvalue=HASHVALUE_NUMERIC;
141 return HASHVALUE_NUMERIC;
142 }
143
144 // new virtual functions which can be overridden by derived classes
145 // (none)
146
147 // non-virtual functions in this class
148 public:
149 numeric add(const numeric & other) const;
150 numeric sub(const numeric & other) const;
151 numeric mul(const numeric & other) const;
152 numeric div(const numeric & other) const;
153 numeric power(const numeric & other) const;
154 const numeric & add_dyn(const numeric & other) const;
155 const numeric & sub_dyn(const numeric & other) const;
156 const numeric & mul_dyn(const numeric & other) const;
157 const numeric & div_dyn(const numeric & other) const;
158 const numeric & power_dyn(const numeric & other) const;
159 const numeric & operator=(int i);
160 const numeric & operator=(unsigned int i);
161 const numeric & operator=(long i);
162 const numeric & operator=(unsigned long i);
163 const numeric & operator=(double d);
164 const numeric & operator=(char const * s);
165 numeric inverse(void) const;
166 int csgn(void) const;
167 int compare(const numeric & other) const;
168 bool is_equal(const numeric & other) const;
169 bool is_zero(void) const;
170 bool is_positive(void) const;
171 bool is_negative(void) const;
172 bool is_integer(void) const;
173 bool is_pos_integer(void) const;
174 bool is_nonneg_integer(void) const;
175 bool is_even(void) const;
176 bool is_odd(void) const;
177 bool is_prime(void) const;
178 bool is_rational(void) const;
179 bool is_real(void) const;
180 bool is_cinteger(void) const;
181 bool is_crational(void) const;
182 bool operator==(const numeric & other) const;
183 bool operator!=(const numeric & other) 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 int to_int(void) const;
189 double to_double(void) const;
190 numeric real(void) const;
191 numeric imag(void) const;
192 numeric numer(void) const;
193 numeric denom(void) const;
194 int int_length(void) const;
195
196 // member variables
197
198 protected:
199 static unsigned precedence;
200 cl_N *value;
201 };
202
203 // global constants
204
205 extern const numeric some_numeric;
206 extern const numeric I;
207 extern type_info const & typeid_numeric;
208 extern _numeric_digits Digits;
209
210 #define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)
211 // may have to be changed to ((x)>=0x80000000U)
212
213 // global functions
214
215 numeric exp(const numeric & x);
216 numeric log(const numeric & x);
217 numeric sin(const numeric & x);
218 numeric cos(const numeric & x);
219 numeric tan(const numeric & x);
220 numeric asin(const numeric & x);
221 numeric acos(const numeric & x);
222 numeric atan(const numeric & x);
223 numeric atan(const numeric & y, const numeric & x);
224 numeric sinh(const numeric & x);
225 numeric cosh(const numeric & x);
226 numeric tanh(const numeric & x);
227 numeric asinh(const numeric & x);
228 numeric acosh(const numeric & x);
229 numeric atanh(const numeric & x);
230 numeric zeta(const numeric & x);
231 numeric gamma(const numeric & x);
232 numeric psi(const numeric & x);
233 numeric psi(const numeric & n, const numeric & x);
234 numeric factorial(const numeric & n);
235 numeric doublefactorial(const numeric & n);
236 numeric binomial(const numeric & n, const numeric & k);
237 numeric bernoulli(const numeric & n);
238
239 numeric abs(const numeric & x);
240 numeric mod(const numeric & a, const numeric & b);
241 numeric smod(const numeric & a, const numeric & b);
242 numeric irem(const numeric & a, const numeric & b);
243 numeric irem(const numeric & a, const numeric & b, numeric & q);
244 numeric iquo(const numeric & a, const numeric & b);
245 numeric iquo(const numeric & a, const numeric & b, numeric & r);
246 numeric sqrt(const numeric & x);
247 numeric isqrt(const numeric & x);
248
249 numeric gcd(const numeric & a, const numeric & b);
250 numeric lcm(const numeric & a, const numeric & b);
251
252 /** Exception thrown by numeric members to signal failure */
253 struct numeric_fail
254 {
255 int failval;
256 numeric_fail(int n) { failval = n; }
257 };
258
259 // wrapper functions around member functions
260 inline numeric pow(const numeric & x, const numeric & y)
261 { return x.power(y); }
262
263 inline numeric inverse(const numeric & x)
264 { return x.inverse(); }
265
266 inline bool csgn(const numeric & x)
267 { return x.csgn(); }
268
269 inline bool is_zero(const numeric & x)
270 { return x.is_zero(); }
271
272 inline bool is_positive(const numeric & x)
273 { return x.is_positive(); }
274
275 inline bool is_integer(const numeric & x)
276 { return x.is_integer(); }
277
278 inline bool is_pos_integer(const numeric & x)
279 { return x.is_pos_integer(); }
280
281 inline bool is_nonneg_integer(const numeric & x)
282 { return x.is_nonneg_integer(); }
283
284 inline bool is_even(const numeric & x)
285 { return x.is_even(); }
286
287 inline bool is_odd(const numeric & x)
288 { return x.is_odd(); }
289
290 inline bool is_prime(const numeric & x)
291 { return x.is_prime(); }
292
293 inline bool is_rational(const numeric & x)
294 { return x.is_rational(); }
295
296 inline bool is_real(const numeric & x)
297 { return x.is_real(); }
298
299 inline bool is_cinteger(const numeric & x)
300 { return x.is_cinteger(); }
301
302 inline bool is_crational(const numeric & x)
303 { return x.is_crational(); }
304
305 inline numeric real(const numeric & x)
306 { return x.real(); }
307
308 inline numeric imag(const numeric & x)
309 { return x.imag(); }
310
311 inline numeric numer(const numeric & x)
312 { return x.numer(); }
313
314 inline numeric denom(const numeric & x)
315 { return x.denom(); }
316
317 // numeric evaluation functions for class constant objects:
318
319 ex PiEvalf(void);
320 ex EulerGammaEvalf(void);
321 ex CatalanEvalf(void);
322
323 // utility functions
324 inline const numeric &ex_to_numeric(const ex &e)
325 {
326 return static_cast<const numeric &>(*e.bp);
327 }
328
329 #ifndef NO_GINAC_NAMESPACE
330 } // namespace GiNaC
331 #endif // ndef NO_GINAC_NAMESPACE
332
333 #endif // ndef __GINAC_NUMERIC_H__

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