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

Diff of /ginac/numeric.h

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

revision 1.33 by cbauer, Thu Apr 6 15:58:15 2000 UTC revision 1.45 by cbauer, Thu Feb 15 19:54:55 2001 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-2000 Johannes Gutenberg University Mainz, Germany   *  GiNaC Copyright (C) 1999-2001 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 27  Line 27 
27  #include "basic.h"  #include "basic.h"
28  #include "ex.h"  #include "ex.h"
29    
30  class cl_N;     // We want to include cln.h only in numeric.cpp in order to  #include <cln/number.h>
31                  // avoid namespace pollution and keep compile-time low.  // forward decln of cln::cl_N, since cln/complex_class.h is not included:
32    namespace cln { class cl_N; }
33    
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>
39    #endif
40    
41  #ifndef NO_NAMESPACE_GINAC  #ifndef NO_NAMESPACE_GINAC
42  namespace GiNaC {  namespace GiNaC {
# Line 52  public: Line 60  public:
60      _numeric_digits();      _numeric_digits();
61      _numeric_digits& operator=(long prec);      _numeric_digits& operator=(long prec);
62      operator long();      operator long();
63      void print(ostream & os) const;          void print(std::ostream & os) const;
64  // member variables  // member variables
65  private:  private:
66      long digits;      long digits;
# Line 65  class numeric : public basic Line 73  class numeric : public basic
73  {  {
74      GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)      GINAC_DECLARE_REGISTERED_CLASS(numeric, basic)
75    
 // friends  
     friend const numeric exp(const numeric & x);  
     friend const numeric log(const numeric & x);  
     friend const numeric sin(const numeric & x);  
     friend const numeric cos(const numeric & x);  
     friend const numeric tan(const numeric & x);  
     friend const numeric asin(const numeric & x);  
     friend const numeric acos(const numeric & x);  
     friend const numeric atan(const numeric & x);  
     friend const numeric atan(const numeric & y, const numeric & x);  
     friend const numeric sinh(const numeric & x);  
     friend const numeric cosh(const numeric & x);  
     friend const numeric tanh(const numeric & x);  
     friend const numeric asinh(const numeric & x);  
     friend const numeric acosh(const numeric & x);  
     friend const numeric atanh(const numeric & x);  
     friend const numeric zeta(const numeric & x);  
     friend const numeric bernoulli(const numeric & n);  
     friend const numeric fibonacci(const numeric & n);  
     friend numeric abs(const numeric & x);  
     friend numeric mod(const numeric & a, const numeric & b);  
     friend numeric smod(const numeric & a, const numeric & b);  
     friend numeric irem(const numeric & a, const numeric & b);  
     friend numeric irem(const numeric & a, const numeric & b, numeric & q);  
     friend numeric iquo(const numeric & a, const numeric & b);  
     friend numeric iquo(const numeric & a, const numeric & b, numeric & r);  
     friend numeric sqrt(const numeric & x);  
     friend numeric isqrt(const numeric & x);  
     friend numeric gcd(const numeric & a, const numeric & b);  
     friend numeric lcm(const numeric & a, const numeric & b);  
   
76  // member functions  // member functions
77    
     // default constructor, destructor, copy constructor assignment  
     // operator and helpers  
 public:  
     numeric();  
     ~numeric();  
     numeric(const numeric & other);  
     const numeric & operator=(const numeric & other);  
 protected:  
     void copy(const numeric & other);  
     void destroy(bool call_parent);  
   
78      // other constructors      // other constructors
79  public:  public:
80      explicit numeric(int i);      explicit numeric(int i);
# Line 118  public: Line 84  public:
84      explicit numeric(long numer, long denom);      explicit numeric(long numer, long denom);
85      explicit numeric(double d);      explicit numeric(double d);
86      explicit numeric(const char *);      explicit numeric(const char *);
     numeric(const cl_N & z);  
87    
88      // functions overriding virtual functions from bases classes      // functions overriding virtual functions from bases classes
89  public:  public:
90      basic * duplicate() const;      basic * duplicate() const;
91      void print(ostream & os, unsigned precedence=0) const;          void print(std::ostream & os, unsigned precedence=0) const;
92      void printraw(ostream & os) const;          void printraw(std::ostream & os) const;
93      void printtree(ostream & os, unsigned indent) const;          void printtree(std::ostream & os, unsigned indent) const;
94      void printcsrc(ostream & os, unsigned type, unsigned precedence=0) const;          void printcsrc(std::ostream & os, unsigned type, unsigned precedence=0) const;
95      bool info(unsigned inf) const;      bool info(unsigned inf) const;
96      bool has(const ex & other) const;      bool has(const ex & other) const;
97      ex eval(int level=0) const;      ex eval(int level=0) const;
# Line 147  protected: Line 112  protected:
112    
113      // non-virtual functions in this class      // non-virtual functions in this class
114  public:  public:
115      numeric add(const numeric & other) const;          const numeric add(const numeric & other) const;
116      numeric sub(const numeric & other) const;          const numeric sub(const numeric & other) const;
117      numeric mul(const numeric & other) const;          const numeric mul(const numeric & other) const;
118      numeric div(const numeric & other) const;          const numeric div(const numeric & other) const;
119      numeric power(const numeric & other) const;          const numeric power(const numeric & other) const;
120      const numeric & add_dyn(const numeric & other) const;      const numeric & add_dyn(const numeric & other) const;
121      const numeric & sub_dyn(const numeric & other) const;      const numeric & sub_dyn(const numeric & other) const;
122      const numeric & mul_dyn(const numeric & other) const;      const numeric & mul_dyn(const numeric & other) const;
# Line 163  public: Line 128  public:
128      const numeric & operator=(unsigned long i);      const numeric & operator=(unsigned long i);
129      const numeric & operator=(double d);      const numeric & operator=(double d);
130      const numeric & operator=(const char * s);      const numeric & operator=(const char * s);
131      numeric inverse(void) const;          const numeric inverse(void) const;
132      int csgn(void) const;      int csgn(void) const;
133      int compare(const numeric & other) const;      int compare(const numeric & other) const;
134      bool is_equal(const numeric & other) const;      bool is_equal(const numeric & other) const;
# Line 189  public: Line 154  public:
154      int to_int(void) const;      int to_int(void) const;
155      long to_long(void) const;      long to_long(void) const;
156      double to_double(void) const;      double to_double(void) const;
157            cln::cl_N to_cl_N(void) const;
158      const numeric real(void) const;      const numeric real(void) const;
159      const numeric imag(void) const;      const numeric imag(void) const;
160      const numeric numer(void) const;      const numeric numer(void) const;
161      const numeric denom(void) const;      const numeric denom(void) const;
162      int int_length(void) const;      int int_length(void) const;
163            // converting routines for interfacing with CLN:
164            numeric(const cln::cl_N & z);
165    
166  // member variables  // member variables
167    
168  protected:  protected:
169      static unsigned precedence;      static unsigned precedence;
170      cl_N *value;          cln::cl_number value;
171  };  };
172    
173  // global constants  // global constants
174    
 extern const numeric some_numeric;  
175  extern const numeric I;  extern const numeric I;
 extern const type_info & typeid_numeric;  
176  extern _numeric_digits Digits;  extern _numeric_digits Digits;
177    
178  //#define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)  //#define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)
# Line 232  const numeric tanh(const numeric & x); Line 198  const numeric tanh(const numeric & x);
198  const numeric asinh(const numeric & x);  const numeric asinh(const numeric & x);
199  const numeric acosh(const numeric & x);  const numeric acosh(const numeric & x);
200  const numeric atanh(const numeric & x);  const numeric atanh(const numeric & x);
201    const numeric Li2(const numeric & x);
202  const numeric zeta(const numeric & x);  const numeric zeta(const numeric & x);
203  const numeric lgamma(const numeric & x);  const numeric lgamma(const numeric & x);
204  const numeric tgamma(const numeric & x);  const numeric tgamma(const numeric & x);
# Line 242  const numeric doublefactorial(const nume Line 209  const numeric doublefactorial(const nume
209  const numeric binomial(const numeric & n, const numeric & k);  const numeric binomial(const numeric & n, const numeric & k);
210  const numeric bernoulli(const numeric & n);  const numeric bernoulli(const numeric & n);
211  const numeric fibonacci(const numeric & n);  const numeric fibonacci(const numeric & n);
212    const numeric abs(const numeric & x);
213  numeric abs(const numeric & x);  const numeric isqrt(const numeric & x);
214  numeric mod(const numeric & a, const numeric & b);  const numeric sqrt(const numeric & x);
215  numeric smod(const numeric & a, const numeric & b);  const numeric abs(const numeric & x);
216  numeric irem(const numeric & a, const numeric & b);  const numeric mod(const numeric & a, const numeric & b);
217  numeric irem(const numeric & a, const numeric & b, numeric & q);  const numeric smod(const numeric & a, const numeric & b);
218  numeric iquo(const numeric & a, const numeric & b);  const numeric irem(const numeric & a, const numeric & b);
219  numeric iquo(const numeric & a, const numeric & b, numeric & r);  const numeric irem(const numeric & a, const numeric & b, numeric & q);
220  numeric sqrt(const numeric & x);  const numeric iquo(const numeric & a, const numeric & b);
221  numeric isqrt(const numeric & x);  const numeric iquo(const numeric & a, const numeric & b, numeric & r);
222    const numeric gcd(const numeric & a, const numeric & b);
223  numeric gcd(const numeric & a, const numeric & b);  const numeric lcm(const numeric & a, const numeric & b);
 numeric lcm(const numeric & a, const numeric & b);  
   
 /** Exception thrown by numeric members to signal failure */  
 struct numeric_fail  
 {  
     int failval;  
     numeric_fail(int n) { failval = n; }  
 };  
224    
225  // wrapper functions around member functions  // wrapper functions around member functions
226  inline numeric pow(const numeric & x, const numeric & y)  inline const numeric pow(const numeric & x, const numeric & y)
227  { return x.power(y); }  { return x.power(y); }
228    
229  inline numeric inverse(const numeric & x)  inline const numeric inverse(const numeric & x)
230  { return x.inverse(); }  { return x.inverse(); }
231    
232  inline int csgn(const numeric & x)  inline int csgn(const numeric & x)
# Line 309  inline bool is_cinteger(const numeric & Line 268  inline bool is_cinteger(const numeric &
268  inline bool is_crational(const numeric & x)  inline bool is_crational(const numeric & x)
269  { return x.is_crational(); }  { return x.is_crational(); }
270    
271    inline int to_int(const numeric & x)
272    { return x.to_int(); }
273    
274    inline long to_long(const numeric & x)
275    { return x.to_long(); }
276    
277    inline double to_double(const numeric & x)
278    { return x.to_double(); }
279    
280  inline const numeric real(const numeric & x)  inline const numeric real(const numeric & x)
281  { return x.real(); }  { return x.real(); }
282    
# Line 339  inline const numeric &ex_to_numeric(cons Line 307  inline const numeric &ex_to_numeric(cons
307  } // namespace GiNaC  } // namespace GiNaC
308  #endif // ndef NO_NAMESPACE_GINAC  #endif // ndef NO_NAMESPACE_GINAC
309    
310    #ifdef __MAKECINT__
311    #pragma link off defined_in cln/number.h;
312    #pragma link off defined_in cln/complex_class.h;
313    #endif
314    
315  #endif // ndef __GINAC_NUMERIC_H__  #endif // ndef __GINAC_NUMERIC_H__

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.45

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