3 * Implementation of GiNaC's constant types and some special constants. */
6 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
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.
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.
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
31 #ifndef NO_GINAC_NAMESPACE
33 #endif // ndef NO_GINAC_NAMESPACE
36 // default constructor, destructor, copy constructor assignment operator and helpers
41 constant::constant() :
42 basic(TINFO_constant), name(""), ef(0),
43 number(0), serial(next_serial++)
45 debugmsg("constant default constructor",LOGLEVEL_CONSTRUCT);
50 debugmsg("constant destructor",LOGLEVEL_DESTRUCT);
54 constant::constant(constant const & other)
56 debugmsg("constant copy constructor",LOGLEVEL_CONSTRUCT);
62 void constant::copy(constant const & other)
68 if (other.number != 0) {
69 number = new numeric(*other.number);
73 // fct_assigned=other.fct_assigned;
76 void constant::destroy(bool call_parent)
80 basic::destroy(call_parent);
89 constant::constant(string const & initname, evalffunctype efun) :
90 basic(TINFO_constant), name(initname), ef(efun),
91 // number(0), fct_assigned(true), serial(next_serial++)
92 number(0), serial(next_serial++)
94 debugmsg("constant constructor from string, function",LOGLEVEL_CONSTRUCT);
97 constant::constant(string const & initname, numeric const & initnumber) :
98 basic(TINFO_constant), name(initname), ef(0),
99 number(new numeric(initnumber)), /* fct_assigned(false),*/ serial(next_serial++)
101 debugmsg("constant constructor from string, numeric",LOGLEVEL_CONSTRUCT);
105 // functions overriding virtual functions from bases classes
110 basic * constant::duplicate() const
112 debugmsg("constant duplicate",LOGLEVEL_DUPLICATE);
113 return new constant(*this);
116 void constant::print(ostream & os, unsigned upper_precedence) const
118 debugmsg("constant print",LOGLEVEL_PRINT);
122 void constant::printraw(ostream & os) const
124 debugmsg("constant printraw",LOGLEVEL_PRINT);
125 os << "constant(" << name << ")";
128 void constant::printtree(ostream & os, unsigned indent) const
130 debugmsg("constant printtree",LOGLEVEL_PRINT);
131 os << string(indent,' ') << name
132 << ", type=" << typeid(*this).name()
133 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
134 << ", flags=" << flags << endl;
137 void constant::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
139 debugmsg("constant print csrc",LOGLEVEL_PRINT);
143 ex constant::evalf(int level) const
147 } else if (number != 0) {
155 int constant::compare_same_type(basic const & other) const
157 GINAC_ASSERT(is_exactly_of_type(other, constant));
158 // constant const & o=static_cast<constant &>(const_cast<basic &>(other));
159 // return name.compare(o.name);
160 const constant *o = static_cast<const constant *>(&other);
161 if (serial==o->serial) return 0;
162 return serial < o->serial ? -1 : 1;
165 bool constant::is_equal_same_type(basic const & other) const
167 GINAC_ASSERT(is_exactly_of_type(other, constant));
168 const constant *o = static_cast<const constant *>(&other);
169 return serial==o->serial;
173 // new virtual functions which can be overridden by derived classes
179 // non-virtual functions in this class
185 // static member variables
188 unsigned constant::next_serial=0;
194 const constant some_constant;
195 type_info const & typeid_constant=typeid(some_constant);
197 /** Pi. (3.14159...) Diverts straight into CLN for evalf(). */
198 const constant Pi("Pi", PiEvalf);
199 /** Catalan's constant. (0.91597...) Diverts straight into CLN for evalf(). */
200 const constant EulerGamma("EulerGamma", EulerGammaEvalf);
201 /** Euler's constant. (0.57721...) Sometimes called Euler-Mascheroni constant.
202 * Diverts straight into CLN for evalf(). */
203 const constant Catalan("Catalan", CatalanEvalf);
205 #ifndef NO_GINAC_NAMESPACE
207 #endif // ndef NO_GINAC_NAMESPACE