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

Diff of /ginac/numeric.h

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

revision 1.1 by cbauer, Tue Nov 9 19:57:04 1999 UTC revision 1.25 by kreckel, Tue Feb 15 20:17:57 2000 UTC
# Line 2  Line 2 
2   *   *
3   *  Makes the interface to the underlying bignum package available. */   *  Makes the interface to the underlying bignum package available. */
4    
5  #ifndef _NUMERIC_H_  /*
6  #define _NUMERIC_H_   *  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  #include <strstream>  #ifndef __GINAC_NUMERIC_H__
24    #define __GINAC_NUMERIC_H__
25    
26  #define HASHVALUE_NUMERIC 0x80000001U  #include <strstream>
27    #include "basic.h"
28    #include "ex.h"
29    
 class numeric;  // Forward declaration, so basic doesn't argue...  
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  #include "basic.h"  
33    #ifndef NO_NAMESPACE_GINAC
34    namespace GiNaC {
35    #endif // ndef NO_NAMESPACE_GINAC
36    
37    #define HASHVALUE_NUMERIC 0x80000001U
38    
39  /** This class is used to instantiate a global object Digits which  /** 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   *  behaves just like Maple's Digits.  We need an object rather than a
# Line 41  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 abs(numeric const & x);      friend const numeric zeta(const numeric & x);
85      friend numeric mod(numeric const & a, numeric const & b);      friend const numeric bernoulli(const numeric & n);
86      friend numeric smod(numeric const & a, numeric const & b);      friend numeric abs(const numeric & x);
87      friend numeric irem(numeric const & a, numeric const & b);      friend numeric mod(const numeric & a, const numeric & b);
88      friend numeric irem(numeric const & a, numeric const & b, numeric & q);      friend numeric smod(const numeric & a, const numeric & b);
89      friend numeric iquo(numeric const & a, numeric const & b);      friend numeric irem(const numeric & a, const numeric & b);
90      friend numeric iquo(numeric const & a, numeric const & b, numeric & r);      friend numeric irem(const numeric & a, const numeric & b, numeric & q);
91      friend numeric sqrt(numeric const & x);      friend numeric iquo(const numeric & a, const numeric & b);
92      friend numeric isqrt(numeric const & x);      friend numeric iquo(const numeric & a, const numeric & b, numeric & r);
93      friend numeric gcd(numeric const & a, numeric const & b);      friend numeric sqrt(const numeric & x);
94      friend numeric lcm(numeric const & a, numeric const & b);      friend numeric isqrt(const numeric & x);
95      friend numeric const & numZERO(void);      friend numeric gcd(const numeric & a, const numeric & b);
96      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);  
97    
98  // member functions  // member functions
99    
# Line 82  class numeric : public basic Line 102  class numeric : public basic
102  public:  public:
103      numeric();      numeric();
104      ~numeric();      ~numeric();
105      numeric(numeric const & other);      numeric(const numeric & other);
106      numeric const & operator=(numeric const & other);      const numeric & operator=(const numeric & other);
107  protected:  protected:
108      void copy(numeric const & other);      void copy(const numeric & other);
109      void destroy(bool call_parent);      void destroy(bool call_parent);
110    
111      // other constructors      // other constructors
# Line 96  public: Line 116  public:
116      explicit numeric(unsigned long i);      explicit numeric(unsigned long i);
117      explicit numeric(long numer, long denom);      explicit numeric(long numer, long denom);
118      explicit numeric(double d);      explicit numeric(double d);
119      explicit numeric(char const *);      explicit numeric(const char *);
120      numeric(cl_N const & z);      numeric(const cl_N & z);
121    
122      // functions overriding virtual functions from bases classes      // functions overriding virtual functions from bases classes
123  public:  public:
124      basic * duplicate() const;      basic * duplicate() const;
125        void print(ostream & os, unsigned precedence=0) const;
126      void printraw(ostream & os) const;      void printraw(ostream & os) const;
127      void printtree(ostream & os, unsigned indent) const;      void printtree(ostream & os, unsigned indent) const;
     void print(ostream & os, unsigned precedence=0) const;  
128      void printcsrc(ostream & os, unsigned type, unsigned precedence=0) const;      void printcsrc(ostream & os, unsigned type, unsigned precedence=0) const;
129      bool info(unsigned inf) const;      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;      ex evalf(int level=0) const;
     ex diff(symbol const & s) const;  
133      ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;      ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
134      numeric integer_content(void) const;      numeric integer_content(void) const;
135      ex smod(numeric const &xi) const;      ex smod(const numeric &xi) const;
136      numeric max_coefficient(void) const;      numeric max_coefficient(void) const;
137  protected:  protected:
138      int compare_same_type(basic const & other) const;      ex derivative(const symbol & s) const;
139      bool is_equal_same_type(basic const & other) const;      int compare_same_type(const basic & other) const;
140        bool is_equal_same_type(const basic & other) const;
141      unsigned calchash(void) const {      unsigned calchash(void) const {
142          hashvalue=HASHVALUE_NUMERIC;          hashvalue=HASHVALUE_NUMERIC;
143          return HASHVALUE_NUMERIC;          return HASHVALUE_NUMERIC;
# Line 126  protected: Line 148  protected:
148    
149      // non-virtual functions in this class      // non-virtual functions in this class
150  public:  public:
151      numeric add(numeric const & other) const;      numeric add(const numeric & other) const;
152      numeric sub(numeric const & other) const;      numeric sub(const numeric & other) const;
153      numeric mul(numeric const & other) const;      numeric mul(const numeric & other) const;
154      numeric div(numeric const & other) const;      numeric div(const numeric & other) const;
155      numeric power(numeric const & other) const;      numeric power(const numeric & other) const;
156      numeric const & add_dyn(numeric const & other) const;      const numeric & add_dyn(const numeric & other) const;
157      numeric const & sub_dyn(numeric const & other) const;      const numeric & sub_dyn(const numeric & other) const;
158      numeric const & mul_dyn(numeric const & other) const;      const numeric & mul_dyn(const numeric & other) const;
159      numeric const & div_dyn(numeric const & other) const;      const numeric & div_dyn(const numeric & other) const;
160      numeric const & power_dyn(numeric const & other) const;      const numeric & power_dyn(const numeric & other) const;
161      numeric const & operator=(int i);      const numeric & operator=(int i);
162      numeric const & operator=(unsigned int i);      const numeric & operator=(unsigned int i);
163      numeric const & operator=(long i);      const numeric & operator=(long i);
164      numeric const & operator=(unsigned long i);      const numeric & operator=(unsigned long i);
165      numeric const & operator=(double d);      const numeric & operator=(double d);
166      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); }  
     */  
167      numeric inverse(void) const;      numeric inverse(void) const;
168      int compare(numeric const & other) const;      int csgn(void) const;
169      bool is_equal(numeric const & other) const;      int compare(const numeric & other) const;
170        bool is_equal(const numeric & other) const;
171      bool is_zero(void) const;      bool is_zero(void) const;
172      bool is_positive(void) const;      bool is_positive(void) const;
173      bool is_negative(void) const;      bool is_negative(void) const;
# Line 163  public: Line 179  public:
179      bool is_prime(void) const;      bool is_prime(void) const;
180      bool is_rational(void) const;      bool is_rational(void) const;
181      bool is_real(void) const;      bool is_real(void) const;
182      bool operator==(numeric const & other) const;      bool is_cinteger(void) const;
183      bool operator!=(numeric const & other) const;      bool is_crational(void) 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>=(numeric const & other) const;      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;      int to_int(void) const;
191        long to_long(void) const;
192      double to_double(void) const;      double to_double(void) const;
193      numeric real(void) const;      numeric real(void) const;
194      numeric imag(void) const;      numeric imag(void) const;
# Line 188  protected: Line 207  protected:
207    
208  extern const numeric some_numeric;  extern const numeric some_numeric;
209  extern const numeric I;  extern const numeric I;
210  extern type_info const & typeid_numeric;  extern const type_info & typeid_numeric;
211  extern _numeric_digits Digits;  extern _numeric_digits Digits;
212    
213  #define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)  #define is_a_numeric_hash(x) ((x)==HASHVALUE_NUMERIC)
# Line 196  extern _numeric_digits Digits; Line 215  extern _numeric_digits Digits;
215    
216  // global functions  // global functions
217    
218  numeric const & numZERO(void);  const numeric exp(const numeric & x);
219  numeric const & numONE(void);  const numeric log(const numeric & x);
220  numeric const & numTWO(void);  const numeric sin(const numeric & x);
221  numeric const & numMINUSONE(void);  const numeric cos(const numeric & x);
222  numeric const & numHALF(void);  const numeric tan(const numeric & x);
223    const numeric asin(const numeric & x);
224  numeric exp(numeric const & x);  const numeric acos(const numeric & x);
225  numeric log(numeric const & x);  const numeric atan(const numeric & x);
226  numeric sin(numeric const & x);  const numeric atan(const numeric & y, const numeric & x);
227  numeric cos(numeric const & x);  const numeric sinh(const numeric & x);
228  numeric tan(numeric const & x);  const numeric cosh(const numeric & x);
229  numeric asin(numeric const & x);  const numeric tanh(const numeric & x);
230  numeric acos(numeric const & x);  const numeric asinh(const numeric & x);
231  numeric atan(numeric const & x);  const numeric acosh(const numeric & x);
232  numeric atan(numeric const & y, numeric const & x);  const numeric atanh(const numeric & x);
233  numeric sinh(numeric const & x);  const numeric zeta(const numeric & x);
234  numeric cosh(numeric const & x);  const numeric gamma(const numeric & x);
235  numeric tanh(numeric const & x);  const numeric psi(const numeric & x);
236  numeric asinh(numeric const & x);  const numeric psi(const numeric & n, const numeric & x);
237  numeric acosh(numeric const & x);  const numeric factorial(const numeric & n);
238  numeric atanh(numeric const & x);  const numeric doublefactorial(const numeric & n);
239  numeric gamma(numeric const & x);  const numeric binomial(const numeric & n, const numeric & k);
240  numeric factorial(numeric const & n);  const numeric bernoulli(const numeric & n);
241  numeric doublefactorial(numeric const & n);  const numeric fibonacci(const numeric & n);
242  numeric binomial(numeric const & n, numeric const & k);  
243    numeric abs(const numeric & x);
244  numeric abs(numeric const & x);  numeric mod(const numeric & a, const numeric & b);
245  numeric mod(numeric const & a, numeric const & b);  numeric smod(const numeric & a, const numeric & b);
246  numeric smod(numeric const & a, numeric const & b);  numeric irem(const numeric & a, const numeric & b);
247  numeric irem(numeric const & a, numeric const & b);  numeric irem(const numeric & a, const numeric & b, numeric & q);
248  numeric irem(numeric const & a, numeric const & b, numeric & q);  numeric iquo(const numeric & a, const numeric & b);
249  numeric iquo(numeric const & a, numeric const & b);  numeric iquo(const numeric & a, const numeric & b, numeric & r);
250  numeric iquo(numeric const & a, numeric const & b, numeric & r);  numeric sqrt(const numeric & x);
251  numeric sqrt(numeric const & x);  numeric isqrt(const numeric & x);
 numeric isqrt(numeric const & x);  
252    
253  numeric gcd(numeric const & a, numeric const & b);  numeric gcd(const numeric & a, const numeric & b);
254  numeric lcm(numeric const & a, numeric const & b);  numeric lcm(const numeric & a, const numeric & b);
255    
256  /** Exception thrown by numeric members to signal failure */  /** Exception thrown by numeric members to signal failure */
257  struct numeric_fail  struct numeric_fail
# Line 243  struct numeric_fail Line 261  struct numeric_fail
261  };  };
262    
263  // wrapper functions around member functions  // wrapper functions around member functions
264  inline numeric inverse(numeric const & x)  inline numeric pow(const numeric & x, const numeric & y)
265    { return x.power(y); }
266    
267    inline numeric inverse(const numeric & x)
268  { return x.inverse(); }  { return x.inverse(); }
269    
270  inline bool is_zero(numeric const & x)  inline bool csgn(const numeric & x)
271    { return x.csgn(); }
272    
273    inline bool is_zero(const numeric & x)
274  { return x.is_zero(); }  { return x.is_zero(); }
275    
276  inline bool is_positive(numeric const & x)  inline bool is_positive(const numeric & x)
277  { return x.is_positive(); }  { return x.is_positive(); }
278    
279  inline bool is_integer(numeric const & x)  inline bool is_integer(const numeric & x)
280  { return x.is_integer(); }  { return x.is_integer(); }
281    
282  inline bool is_pos_integer(numeric const & x)  inline bool is_pos_integer(const numeric & x)
283  { return x.is_pos_integer(); }  { return x.is_pos_integer(); }
284    
285  inline bool is_nonneg_integer(numeric const & x)  inline bool is_nonneg_integer(const numeric & x)
286  { return x.is_nonneg_integer(); }  { return x.is_nonneg_integer(); }
287    
288  inline bool is_even(numeric const & x)  inline bool is_even(const numeric & x)
289  { return x.is_even(); }  { return x.is_even(); }
290    
291  inline bool is_odd(numeric const & x)  inline bool is_odd(const numeric & x)
292  { return x.is_odd(); }  { return x.is_odd(); }
293    
294  inline bool is_prime(numeric const & x)  inline bool is_prime(const numeric & x)
295  { return x.is_prime(); }  { return x.is_prime(); }
296    
297  inline bool is_rational(numeric const & x)  inline bool is_rational(const numeric & x)
298  { return x.is_rational(); }  { return x.is_rational(); }
299    
300  inline bool is_real(numeric const & x)  inline bool is_real(const numeric & x)
301  { return x.is_real(); }  { return x.is_real(); }
302    
303  inline numeric real(numeric const & x)  inline bool is_cinteger(const numeric & x)
304    { return x.is_cinteger(); }
305    
306    inline bool is_crational(const numeric & x)
307    { return x.is_crational(); }
308    
309    inline numeric real(const numeric & x)
310  { return x.real(); }  { return x.real(); }
311    
312  inline numeric imag(numeric const & x)  inline numeric imag(const numeric & x)
313  { return x.imag(); }  { return x.imag(); }
314    
315  inline numeric numer(numeric const & x)  inline numeric numer(const numeric & x)
316  { return x.numer(); }  { return x.numer(); }
317    
318  inline numeric denom(numeric const & x)  inline numeric denom(const numeric & x)
319  { return x.denom(); }  { return x.denom(); }
320    
321  /* do we need this any more? */  // numeric evaluation functions for class constant objects:
 //inline numeric factorial(int n)  
 //{ return factorial(numeric(n)); }  
   
 /* do we need this any more? */  
 //inline numeric binomial(int n, int k)  
 //{ return binomial(numeric(n), numeric(k)); }  
322    
 ex IEvalf(void);  
323  ex PiEvalf(void);  ex PiEvalf(void);
324  ex EulerGammaEvalf(void);  ex EulerGammaEvalf(void);
325  ex CatalanEvalf(void);  ex CatalanEvalf(void);
326    
 #define ex_to_numeric(X) static_cast<numeric const &>(*(X).bp)  
327    
328    // utility functions
329    inline const numeric &ex_to_numeric(const ex &e)
330    {
331        return static_cast<const numeric &>(*e.bp);
332    }
333    
334    
335    #ifndef NO_NAMESPACE_GINAC
336    } // namespace GiNaC
337    #endif // ndef NO_NAMESPACE_GINAC
338    
339  #endif // ndef _NUMERIC_H_  #endif // ndef __GINAC_NUMERIC_H__

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.25

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