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

Diff of /ginac/numeric.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by kreckel, Mon Nov 29 19:50:48 1999 UTC revision 1.34 by kreckel, Mon Jun 5 09:45:21 2000 UTC
# Line 3  Line 3 
3   *  Makes the interface to the underlying bignum package available. */   *  Makes the interface to the underlying bignum package available. */
4    
5  /*  /*
6   *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany   *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
7   *   *
8   *  This program is free software; you can redistribute it and/or modify   *  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   *  it under the terms of the GNU General Public License as published by
# Line 24  Line 24 
24  #define __GINAC_NUMERIC_H__  #define __GINAC_NUMERIC_H__
25    
26  #include <strstream>  #include <strstream>
27  #include <ginac/basic.h>  #include "basic.h"
28  #include <ginac/ex.h>  #include "ex.h"
29    
30  class cl_N;     // We want to include cln.h only in numeric.cpp in order to  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.                  // avoid namespace pollution and keep compile-time low.
32    
33    #ifndef NO_NAMESPACE_GINAC
34  namespace GiNaC {  namespace GiNaC {
35    #endif // ndef NO_NAMESPACE_GINAC
36    
37  #define HASHVALUE_NUMERIC 0x80000001U  #define HASHVALUE_NUMERIC 0x80000001U
38    
# Line 61  private: Line 63  private:
63   *  hierarchy. Objects of this type may directly be created by the user.*/   *  hierarchy. Objects of this type may directly be created by the user.*/
64  class numeric : public basic  class numeric : public basic
65  {  {
66        GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)
67    
68  // friends  // friends
69      friend numeric exp(numeric const & x);      friend const numeric exp(const numeric & x);
70      friend numeric log(numeric const & x);      friend const numeric log(const numeric & x);
71      friend numeric sin(numeric const & x);      friend const numeric sin(const numeric & x);
72      friend numeric cos(numeric const & x);      friend const numeric cos(const numeric & x);
73      friend numeric tan(numeric const & x);      friend const numeric tan(const numeric & x);
74      friend numeric asin(numeric const & x);      friend const numeric asin(const numeric & x);
75      friend numeric acos(numeric const & x);      friend const numeric acos(const numeric & x);
76      friend numeric atan(numeric const & x);      friend const numeric atan(const numeric & x);
77      friend numeric atan(numeric const & y, numeric const & x);      friend const numeric atan(const numeric & y, const numeric & x);
78      friend numeric sinh(numeric const & x);      friend const numeric sinh(const numeric & x);
79      friend numeric cosh(numeric const & x);      friend const numeric cosh(const numeric & x);
80      friend numeric tanh(numeric const & x);      friend const numeric tanh(const numeric & x);
81      friend numeric asinh(numeric const & x);      friend const numeric asinh(const numeric & x);
82      friend numeric acosh(numeric const & x);      friend const numeric acosh(const numeric & x);
83      friend numeric atanh(numeric const & x);      friend const numeric atanh(const numeric & x);
84      friend numeric bernoulli(numeric const & n);      friend const numeric zeta(const numeric & x);
85      friend numeric abs(numeric const & x);      friend const numeric bernoulli(const numeric & n);
86      friend numeric mod(numeric const & a, numeric const & b);      friend const numeric fibonacci(const numeric & n);
87      friend numeric smod(numeric const & a, numeric const & b);      friend numeric abs(const numeric & x);
88      friend numeric irem(numeric const & a, numeric const & b);      friend numeric mod(const numeric & a, const numeric & b);
89      friend numeric irem(numeric const & a, numeric const & b, numeric & q);      friend numeric smod(const numeric & a, const numeric & b);
90      friend numeric iquo(numeric const & a, numeric const & b);      friend numeric irem(const numeric & a, const numeric & b);
91      friend numeric iquo(numeric const & a, numeric const & b, numeric & r);      friend numeric irem(const numeric & a, const numeric & b, numeric & q);
92      friend numeric sqrt(numeric const & x);      friend numeric iquo(const numeric & a, const numeric & b);
93      friend numeric isqrt(numeric const & x);      friend numeric iquo(const numeric & a, const numeric & b, numeric & r);
94      friend numeric gcd(numeric const & a, numeric const & b);      friend numeric sqrt(const numeric & x);
95      friend numeric lcm(numeric const & a, numeric const & b);      friend numeric isqrt(const numeric & x);
96      friend numeric const & numZERO(void);      friend numeric gcd(const numeric & a, const numeric & b);
97      friend numeric const & numONE(void);      friend numeric lcm(const numeric & a, const numeric & b);
     friend numeric const & numTWO(void);  
     friend numeric const & numTHREE(void);  
     friend numeric const & numMINUSONE(void);  
     friend numeric const & numHALF(void);  
98    
99  // member functions  // member functions
100    
# Line 103  class numeric : public basic Line 103  class numeric : public basic
103  public:  public:
104      numeric();      numeric();
105      ~numeric();      ~numeric();
106      numeric(numeric const & other);      numeric(const numeric & other);
107      numeric const & operator=(numeric const & other);      const numeric & operator=(const numeric & other);
108  protected:  protected:
109      void copy(numeric const & other);      void copy(const numeric & other);
110      void destroy(bool call_parent);      void destroy(bool call_parent);
111    
112      // other constructors      // other constructors
# Line 117  public: Line 117  public:
117      explicit numeric(unsigned long i);      explicit numeric(unsigned long i);
118      explicit numeric(long numer, long denom);      explicit numeric(long numer, long denom);
119      explicit numeric(double d);      explicit numeric(double d);
120      explicit numeric(char const *);      explicit numeric(const char *);
121      numeric(cl_N const & z);      numeric(const cl_N & z);
122    
123      // functions overriding virtual functions from bases classes      // functions overriding virtual functions from bases classes
124  public:  public:
125      basic * duplicate() const;      basic * duplicate() const;
126        void print(ostream & os, unsigned precedence=0) const;
127      void printraw(ostream & os) const;      void printraw(ostream & os) const;
128      void printtree(ostream & os, unsigned indent) const;      void printtree(ostream & os, unsigned indent) const;
     void print(ostream & os, unsigned precedence=0) const;  
129      void printcsrc(ostream & os, unsigned type, unsigned precedence=0) const;      void printcsrc(ostream & os, unsigned type, unsigned precedence=0) const;
130      bool info(unsigned inf) const;      bool info(unsigned inf) const;
131        bool has(const ex & other) const;
132        ex eval(int level=0) const;
133      ex evalf(int level=0) const;      ex evalf(int level=0) const;
     ex diff(symbol const & s) const;  
134      ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;      ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
135        ex to_rational(lst &repl_lst) const;
136      numeric integer_content(void) const;      numeric integer_content(void) const;
137      ex smod(numeric const &xi) const;      ex smod(const numeric &xi) const;
138      numeric max_coefficient(void) const;      numeric max_coefficient(void) const;
139  protected:  protected:
140      int compare_same_type(basic const & other) const;      ex derivative(const symbol & s) const;
141      bool is_equal_same_type(basic const & other) const;      int compare_same_type(const basic & other) const;
142      unsigned calchash(void) const {      bool is_equal_same_type(const basic & other) const;
143          hashvalue=HASHVALUE_NUMERIC;      unsigned calchash(void) const;
         return HASHVALUE_NUMERIC;  
     }  
144    
145      // new virtual functions which can be overridden by derived classes      // new virtual functions which can be overridden by derived classes
146      // (none)      // (none)
147    
148      // non-virtual functions in this class      // non-virtual functions in this class
149  public:  public:
150      numeric add(numeric const & other) const;      numeric add(const numeric & other) const;
151      numeric sub(numeric const & other) const;      numeric sub(const numeric & other) const;
152      numeric mul(numeric const & other) const;      numeric mul(const numeric & other) const;
153      numeric div(numeric const & other) const;      numeric div(const numeric & other) const;
154      numeric power(numeric const & other) const;      numeric power(const numeric & other) const;
155      numeric const & add_dyn(numeric const & other) const;      const numeric & add_dyn(const numeric & other) const;
156      numeric const & sub_dyn(numeric const & other) const;      const numeric & sub_dyn(const numeric & other) const;
157      numeric const & mul_dyn(numeric const & other) const;      const numeric & mul_dyn(const numeric & other) const;
158      numeric const & div_dyn(numeric const & other) const;      const numeric & div_dyn(const numeric & other) const;
159      numeric const & power_dyn(numeric const & other) const;      const numeric & power_dyn(const numeric & other) const;
160      numeric const & operator=(int i);      const numeric & operator=(int i);
161      numeric const & operator=(unsigned int i);      const numeric & operator=(unsigned int i);
162      numeric const & operator=(long i);      const numeric & operator=(long i);
163      numeric const & operator=(unsigned long i);      const numeric & operator=(unsigned long i);
164      numeric const & operator=(double d);      const numeric & operator=(double d);
165      numeric const & operator=(char const * s);      const numeric & operator=(const char * s);
     /*  
     numeric add_dyn(numeric const & other) const   { return add(other);   }  
     numeric sub_dyn(numeric const & other) const   { return sub(other);   }  
     numeric mul_dyn(numeric const & other) const   { return mul(other);   }  
     numeric div_dyn(numeric const & other) const   { return div(other);   }  
     numeric power_dyn(numeric const & other) const { return power(other); }  
     */  
166      numeric inverse(void) const;      numeric inverse(void) const;
167      int csgn(void) const;      int csgn(void) const;
168      int compare(numeric const & other) const;      int compare(const numeric & other) const;
169      bool is_equal(numeric const & other) const;      bool is_equal(const numeric & other) const;
170      bool is_zero(void) const;      bool is_zero(void) const;
171      bool is_positive(void) const;      bool is_positive(void) const;
172      bool is_negative(void) const;      bool is_negative(void) const;
# Line 185  public: Line 178  public:
178      bool is_prime(void) const;      bool is_prime(void) const;
179      bool is_rational(void) const;      bool is_rational(void) const;
180      bool is_real(void) const;      bool is_real(void) const;
181      bool operator==(numeric const & other) const;      bool is_cinteger(void) const;
182      bool operator!=(numeric const & other) const;      bool is_crational(void) const;
183      bool operator<(numeric const & other) const;      bool operator==(const numeric & other) const;
184      bool operator<=(numeric const & other) const;      bool operator!=(const numeric & other) const;
185      bool operator>(numeric const & other) const;      bool operator<(const numeric & other) const;
186      bool operator>=(numeric const & other) const;      bool operator<=(const numeric & other) const;
187        bool operator>(const numeric & other) const;
188        bool operator>=(const numeric & other) const;
189      int to_int(void) const;      int to_int(void) const;
190        long to_long(void) const;
191      double to_double(void) const;      double to_double(void) const;
192      numeric real(void) const;      const numeric real(void) const;
193      numeric imag(void) const;      const numeric imag(void) const;
194      numeric numer(void) const;      const numeric numer(void) const;
195      numeric denom(void) const;      const numeric denom(void) const;
196      int int_length(void) const;      int int_length(void) const;
197    
198  // member variables  // member variables
# Line 210  protected: Line 206  protected:
206    
207  extern const numeric some_numeric;  extern const numeric some_numeric;
208  extern const numeric I;  extern const numeric I;
209  extern type_info const & typeid_numeric;  extern const type_info & typeid_numeric;
210  extern _numeric_digits Digits;  extern _numeric_digits Digits;
211    
212  #define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)  //#define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)
213  // may have to be changed to ((x)>=0x80000000U)  // may have to be changed to ((x)>=0x80000000U)
214    
215  // global functions  // has been changed
216    //#define is_a_numeric_hash(x) ((x)&0x80000000U)
217    
218  numeric const & numZERO(void);  // global functions
 numeric const & numONE(void);  
 numeric const & numTWO(void);  
 numeric const & numMINUSONE(void);  
 numeric const & numHALF(void);  
   
 numeric exp(numeric const & x);  
 numeric log(numeric const & x);  
 numeric sin(numeric const & x);  
 numeric cos(numeric const & x);  
 numeric tan(numeric const & x);  
 numeric asin(numeric const & x);  
 numeric acos(numeric const & x);  
 numeric atan(numeric const & x);  
 numeric atan(numeric const & y, numeric const & x);  
 numeric sinh(numeric const & x);  
 numeric cosh(numeric const & x);  
 numeric tanh(numeric const & x);  
 numeric asinh(numeric const & x);  
 numeric acosh(numeric const & x);  
 numeric atanh(numeric const & x);  
 numeric zeta(numeric const & x);  
 numeric gamma(numeric const & x);  
 numeric psi(numeric const & x);  
 numeric psi(numeric const & n, numeric const & x);  
 numeric factorial(numeric const & n);  
 numeric doublefactorial(numeric const & n);  
 numeric binomial(numeric const & n, numeric const & k);  
 numeric bernoulli(numeric const & n);  
   
 numeric abs(numeric const & x);  
 numeric mod(numeric const & a, numeric const & b);  
 numeric smod(numeric const & a, numeric const & b);  
 numeric irem(numeric const & a, numeric const & b);  
 numeric irem(numeric const & a, numeric const & b, numeric & q);  
 numeric iquo(numeric const & a, numeric const & b);  
 numeric iquo(numeric const & a, numeric const & b, numeric & r);  
 numeric sqrt(numeric const & x);  
 numeric isqrt(numeric const & x);  
219    
220  numeric gcd(numeric const & a, numeric const & b);  const numeric exp(const numeric & x);
221  numeric lcm(numeric const & a, numeric const & b);  const numeric log(const numeric & x);
222    const numeric sin(const numeric & x);
223    const numeric cos(const numeric & x);
224    const numeric tan(const numeric & x);
225    const numeric asin(const numeric & x);
226    const numeric acos(const numeric & x);
227    const numeric atan(const numeric & x);
228    const numeric atan(const numeric & y, const numeric & x);
229    const numeric sinh(const numeric & x);
230    const numeric cosh(const numeric & x);
231    const numeric tanh(const numeric & x);
232    const numeric asinh(const numeric & x);
233    const numeric acosh(const numeric & x);
234    const numeric atanh(const numeric & x);
235    const numeric zeta(const numeric & x);
236    const numeric lgamma(const numeric & x);
237    const numeric tgamma(const numeric & x);
238    const numeric psi(const numeric & x);
239    const numeric psi(const numeric & n, const numeric & x);
240    const numeric factorial(const numeric & n);
241    const numeric doublefactorial(const numeric & n);
242    const numeric binomial(const numeric & n, const numeric & k);
243    const numeric bernoulli(const numeric & n);
244    const numeric fibonacci(const numeric & n);
245    
246    numeric abs(const numeric & x);
247    numeric mod(const numeric & a, const numeric & b);
248    numeric smod(const numeric & a, const numeric & b);
249    numeric irem(const numeric & a, const numeric & b);
250    numeric irem(const numeric & a, const numeric & b, numeric & q);
251    numeric iquo(const numeric & a, const numeric & b);
252    numeric iquo(const numeric & a, const numeric & b, numeric & r);
253    numeric sqrt(const numeric & x);
254    numeric isqrt(const numeric & x);
255    
256  /** Exception thrown by numeric members to signal failure */  numeric gcd(const numeric & a, const numeric & b);
257  struct numeric_fail  numeric lcm(const numeric & a, const numeric & b);
 {  
     int failval;  
     numeric_fail(int n) { failval = n; }  
 };  
258    
259  // wrapper functions around member functions  // wrapper functions around member functions
260  inline numeric inverse(numeric const & x)  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(); }  { return x.inverse(); }
265    
266  inline bool csgn(numeric const & x)  inline int csgn(const numeric & x)
267  { return x.csgn(); }  { return x.csgn(); }
268    
269  inline bool is_zero(numeric const & x)  inline bool is_zero(const numeric & x)
270  { return x.is_zero(); }  { return x.is_zero(); }
271    
272  inline bool is_positive(numeric const & x)  inline bool is_positive(const numeric & x)
273  { return x.is_positive(); }  { return x.is_positive(); }
274    
275  inline bool is_integer(numeric const & x)  inline bool is_integer(const numeric & x)
276  { return x.is_integer(); }  { return x.is_integer(); }
277    
278  inline bool is_pos_integer(numeric const & x)  inline bool is_pos_integer(const numeric & x)
279  { return x.is_pos_integer(); }  { return x.is_pos_integer(); }
280    
281  inline bool is_nonneg_integer(numeric const & x)  inline bool is_nonneg_integer(const numeric & x)
282  { return x.is_nonneg_integer(); }  { return x.is_nonneg_integer(); }
283    
284  inline bool is_even(numeric const & x)  inline bool is_even(const numeric & x)
285  { return x.is_even(); }  { return x.is_even(); }
286    
287  inline bool is_odd(numeric const & x)  inline bool is_odd(const numeric & x)
288  { return x.is_odd(); }  { return x.is_odd(); }
289    
290  inline bool is_prime(numeric const & x)  inline bool is_prime(const numeric & x)
291  { return x.is_prime(); }  { return x.is_prime(); }
292    
293  inline bool is_rational(numeric const & x)  inline bool is_rational(const numeric & x)
294  { return x.is_rational(); }  { return x.is_rational(); }
295    
296  inline bool is_real(numeric const & x)  inline bool is_real(const numeric & x)
297  { return x.is_real(); }  { return x.is_real(); }
298    
299  inline numeric real(numeric const & x)  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 const numeric real(const numeric & x)
306  { return x.real(); }  { return x.real(); }
307    
308  inline numeric imag(numeric const & x)  inline const numeric imag(const numeric & x)
309  { return x.imag(); }  { return x.imag(); }
310    
311  inline numeric numer(numeric const & x)  inline const numeric numer(const numeric & x)
312  { return x.numer(); }  { return x.numer(); }
313    
314  inline numeric denom(numeric const & x)  inline const numeric denom(const numeric & x)
315  { return x.denom(); }  { return x.denom(); }
316    
317  ex IEvalf(void);  // numeric evaluation functions for class constant objects:
318    
319  ex PiEvalf(void);  ex PiEvalf(void);
320  ex EulerGammaEvalf(void);  ex EulerEvalf(void);
321  ex CatalanEvalf(void);  ex CatalanEvalf(void);
322    
323    
324  // utility functions  // utility functions
325  inline const numeric &ex_to_numeric(const ex &e)  inline const numeric &ex_to_numeric(const ex &e)
326  {  {
327          return static_cast<const numeric &>(*e.bp);          return static_cast<const numeric &>(*e.bp);
328  }  }
329    
330    
331    #ifndef NO_NAMESPACE_GINAC
332  } // namespace GiNaC  } // namespace GiNaC
333    #endif // ndef NO_NAMESPACE_GINAC
334    
335  #endif // ndef __GINAC_NUMERIC_H__  #endif // ndef __GINAC_NUMERIC_H__

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.34

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