3 * Implementation of GiNaC's constant types and some special constants.
5 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 // default constructor, destructor, copy constructor assignment operator and helpers
37 debugmsg("constant destructor",LOGLEVEL_DESTRUCT);
41 constant::constant(constant const & other)
43 debugmsg("constant copy constructor",LOGLEVEL_CONSTRUCT);
49 void constant::copy(constant const & other)
55 if (other.number != 0) {
56 number = new numeric(*other.number);
60 fct_assigned=other.fct_assigned;
63 void constant::destroy(bool call_parent)
67 basic::destroy(call_parent);
76 constant::constant(string const & initname, ex (*efun)()) :
77 basic(TINFO_constant), name(initname), ef(efun),
78 number(0), fct_assigned(true), serial(next_serial++)
80 debugmsg("constant constructor from string, function",LOGLEVEL_CONSTRUCT);
83 constant::constant(string const & initname, numeric const & initnumber) :
84 basic(TINFO_constant), name(initname), ef(0),
85 number(new numeric(initnumber)), fct_assigned(false), serial(next_serial++)
87 debugmsg("constant constructor from string, numeric",LOGLEVEL_CONSTRUCT);
91 // functions overriding virtual functions from bases classes
96 basic * constant::duplicate() const
98 debugmsg("constant duplicate",LOGLEVEL_DUPLICATE);
99 return new constant(*this);
102 ex constant::evalf(int level) const
106 } else if (number != 0) {
114 int constant::compare_same_type(basic const & other) const
116 ASSERT(is_exactly_of_type(other, constant));
117 // constant const & o=static_cast<constant &>(const_cast<basic &>(other));
118 // return name.compare(o.name);
119 const constant *o = static_cast<const constant *>(&other);
120 if (serial==o->serial) return 0;
121 return serial < o->serial ? -1 : 1;
124 bool constant::is_equal_same_type(basic const & other) const
126 ASSERT(is_exactly_of_type(other, constant));
127 const constant *o = static_cast<const constant *>(&other);
128 return serial==o->serial;
132 // new virtual functions which can be overridden by derived classes
138 // non-virtual functions in this class
144 // static member variables
147 unsigned constant::next_serial=0;
153 const constant some_constant("",0);
154 type_info const & typeid_constant=typeid(some_constant);
156 /** Pi. (3.14159...) Diverts straight into CLN for evalf(). */
157 const constant Pi("Pi", PiEvalf);
158 /** Catalan's constant. (0.91597...) Diverts straight into CLN for evalf(). */
159 const constant EulerGamma("EulerGamma", EulerGammaEvalf);
160 /** Euler's constant. (0.57721...) Sometimes called Euler-Mascheroni constant.
161 * Diverts straight into CLN for evalf(). */
162 const constant Catalan("Catalan", CatalanEvalf);