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
28 // default constructor, destructor, copy constructor assignment operator and helpers
35 debugmsg("constant destructor",LOGLEVEL_DESTRUCT);
39 constant::constant(constant const & other)
41 debugmsg("constant copy constructor",LOGLEVEL_CONSTRUCT);
47 void constant::copy(constant const & other)
53 if (other.number != 0) {
54 number = new numeric(*other.number);
58 fct_assigned=other.fct_assigned;
61 void constant::destroy(bool call_parent)
65 basic::destroy(call_parent);
74 constant::constant(string const & initname, ex (*efun)()) :
75 basic(TINFO_CONSTANT), name(initname), ef(efun),
76 number(0), fct_assigned(true), serial(next_serial++)
78 debugmsg("constant constructor from string, function",LOGLEVEL_CONSTRUCT);
81 constant::constant(string const & initname, numeric const & initnumber) :
82 basic(TINFO_CONSTANT), name(initname), ef(0),
83 number(new numeric(initnumber)), fct_assigned(false), serial(next_serial++)
85 debugmsg("constant constructor from string, numeric",LOGLEVEL_CONSTRUCT);
89 // functions overriding virtual functions from bases classes
94 basic * constant::duplicate() const
96 debugmsg("constant duplicate",LOGLEVEL_DUPLICATE);
97 return new constant(*this);
100 ex constant::evalf(int level) const
104 } else if (number != 0) {
112 int constant::compare_same_type(basic const & other) const
114 ASSERT(is_exactly_of_type(other, constant));
115 // constant const & o=static_cast<constant &>(const_cast<basic &>(other));
116 // return name.compare(o.name);
117 const constant *o = static_cast<const constant *>(&other);
118 if (serial==o->serial) return 0;
119 return serial < o->serial ? -1 : 1;
122 bool constant::is_equal_same_type(basic const & other) const
124 ASSERT(is_exactly_of_type(other, constant));
125 const constant *o = static_cast<const constant *>(&other);
126 return serial==o->serial;
130 // new virtual functions which can be overridden by derived classes
136 // non-virtual functions in this class
142 // static member variables
145 unsigned constant::next_serial=0;
151 const constant some_constant("",0);
152 type_info const & typeid_constant=typeid(some_constant);
154 /** Pi. (3.14159...) Diverts straight into CLN for evalf(). */
155 const constant Pi("Pi", PiEvalf);
156 /** Catalan's constant. (0.91597...) Diverts straight into CLN for evalf(). */
157 const constant EulerGamma("EulerGamma", EulerGammaEvalf);
158 /** Euler's constant. (0.57721...) Sometimes called Euler-Mascheroni constant.
159 * Diverts straight into CLN for evalf(). */
160 const constant Catalan("Catalan", CatalanEvalf);