3 * Implementation of GiNaC's constant types and some special constants. */
11 // default constructor, destructor, copy constructor assignment operator and helpers
18 debugmsg("constant destructor",LOGLEVEL_DESTRUCT);
22 constant::constant(constant const & other)
24 debugmsg("constant copy constructor",LOGLEVEL_CONSTRUCT);
30 void constant::copy(constant const & other)
36 if (other.number != 0) {
37 number = new numeric(*other.number);
41 fct_assigned=other.fct_assigned;
44 void constant::destroy(bool call_parent)
48 basic::destroy(call_parent);
57 constant::constant(string const & initname, ex (*efun)()) :
58 basic(TINFO_CONSTANT), name(initname), ef(efun),
59 number(0), fct_assigned(true), serial(next_serial++)
61 debugmsg("constant constructor from string, function",LOGLEVEL_CONSTRUCT);
64 constant::constant(string const & initname, numeric const & initnumber) :
65 basic(TINFO_CONSTANT), name(initname), ef(0),
66 number(new numeric(initnumber)), fct_assigned(false), serial(next_serial++)
68 debugmsg("constant constructor from string, numeric",LOGLEVEL_CONSTRUCT);
72 // functions overriding virtual functions from bases classes
77 basic * constant::duplicate() const
79 debugmsg("constant duplicate",LOGLEVEL_DUPLICATE);
80 return new constant(*this);
83 ex constant::evalf(int level) const
87 } else if (number != 0) {
95 int constant::compare_same_type(basic const & other) const
97 ASSERT(is_exactly_of_type(other, constant));
98 // constant const & o=static_cast<constant &>(const_cast<basic &>(other));
99 // return name.compare(o.name);
100 const constant *o = static_cast<const constant *>(&other);
101 if (serial==o->serial) return 0;
102 return serial < o->serial ? -1 : 1;
105 bool constant::is_equal_same_type(basic const & other) const
107 ASSERT(is_exactly_of_type(other, constant));
108 const constant *o = static_cast<const constant *>(&other);
109 return serial==o->serial;
113 // new virtual functions which can be overridden by derived classes
119 // non-virtual functions in this class
125 // static member variables
128 unsigned constant::next_serial=0;
134 const constant some_constant("",0);
135 type_info const & typeid_constant=typeid(some_constant);
137 /** Pi. (3.14159...) Diverts straight into CLN for evalf(). */
138 const constant Pi("Pi", PiEvalf);
139 /** Catalan's constant. (0.91597...) Diverts straight into CLN for evalf(). */
140 const constant EulerGamma("EulerGamma", EulerGammaEvalf);
141 /** Euler's constant. (0.57721...) Sometimes called Euler-Mascheroni constant.
142 * Diverts straight into CLN for evalf(). */
143 const constant Catalan("Catalan", CatalanEvalf);