1 /** @file operators.cpp
3 * Implementation of GiNaC's overloaded operators. */
6 * GiNaC Copyright (C) 1999-2001 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
26 #include "operators.h"
31 #include "relational.h"
35 #ifndef NO_NAMESPACE_GINAC
37 #endif // ndef NO_NAMESPACE_GINAC
39 // binary arithmetic operators ex with ex
41 ex operator+(const ex & lh, const ex & rh)
43 debugmsg("operator+(ex,ex)",LOGLEVEL_OPERATOR);
47 ex operator-(const ex & lh, const ex & rh)
49 debugmsg("operator-(ex,ex)",LOGLEVEL_OPERATOR);
50 return lh.exadd(rh.exmul(_ex_1()));
53 ex operator*(const ex & lh, const ex & rh)
55 debugmsg("operator*(ex,ex)",LOGLEVEL_OPERATOR);
59 ex operator/(const ex & lh, const ex & rh)
61 debugmsg("operator/(ex,ex)",LOGLEVEL_OPERATOR);
62 return lh.exmul(power(rh,_ex_1()));
65 ex operator%(const ex & lh, const ex & rh)
67 debugmsg("operator%(ex,ex)",LOGLEVEL_OPERATOR);
68 return lh.exncmul(rh);
72 // binary arithmetic operators numeric with numeric
74 numeric operator+(const numeric & lh, const numeric & rh)
76 debugmsg("operator+(numeric,numeric)",LOGLEVEL_OPERATOR);
80 numeric operator-(const numeric & lh, const numeric & rh)
82 debugmsg("operator-(numeric,numeric)",LOGLEVEL_OPERATOR);
86 numeric operator*(const numeric & lh, const numeric & rh)
88 debugmsg("operator*(numeric,numeric)",LOGLEVEL_OPERATOR);
92 numeric operator/(const numeric & lh, const numeric & rh)
94 debugmsg("operator/(numeric,ex)",LOGLEVEL_OPERATOR);
99 // binary arithmetic assignment operators with ex
101 const ex & operator+=(ex & lh, const ex & rh)
103 debugmsg("operator+=(ex,ex)",LOGLEVEL_OPERATOR);
107 const ex & operator-=(ex & lh, const ex & rh)
109 debugmsg("operator-=(ex,ex)",LOGLEVEL_OPERATOR);
113 const ex & operator*=(ex & lh, const ex & rh)
115 debugmsg("operator*=(ex,ex)",LOGLEVEL_OPERATOR);
119 const ex & operator/=(ex & lh, const ex & rh)
121 debugmsg("operator/=(ex,ex)",LOGLEVEL_OPERATOR);
125 const ex & operator%=(ex & lh, const ex & rh)
127 debugmsg("operator%=(ex,ex)",LOGLEVEL_OPERATOR);
132 // binary arithmetic assignment operators with numeric
134 const numeric & operator+=(numeric & lh, const numeric & rh)
136 debugmsg("operator+=(numeric,numeric)",LOGLEVEL_OPERATOR);
137 return (lh=lh.add(rh));
140 const numeric & operator-=(numeric & lh, const numeric & rh)
142 debugmsg("operator-=(numeric,numeric)",LOGLEVEL_OPERATOR);
143 return (lh=lh.sub(rh));
146 const numeric & operator*=(numeric & lh, const numeric & rh)
148 debugmsg("operator*=(numeric,numeric)",LOGLEVEL_OPERATOR);
149 return (lh=lh.mul(rh));
152 const numeric & operator/=(numeric & lh, const numeric & rh)
154 debugmsg("operator/=(numeric,numeric)",LOGLEVEL_OPERATOR);
155 return (lh=lh.div(rh));
160 ex operator+(const ex & lh)
162 debugmsg("operator+(ex)",LOGLEVEL_OPERATOR);
166 ex operator-(const ex & lh)
168 debugmsg("operator-(ex)",LOGLEVEL_OPERATOR);
169 return lh.exmul(_ex_1());
172 numeric operator+(const numeric & lh)
174 debugmsg("operator+(numeric)",LOGLEVEL_OPERATOR);
178 numeric operator-(const numeric & lh)
180 debugmsg("operator-(numeric)",LOGLEVEL_OPERATOR);
184 /** Numeric prefix increment. Adds 1 and returns incremented number. */
185 numeric& operator++(numeric & rh)
187 debugmsg("operator++(numeric)",LOGLEVEL_OPERATOR);
192 /** Numeric prefix decrement. Subtracts 1 and returns decremented number. */
193 numeric& operator--(numeric & rh)
195 debugmsg("operator--(numeric)",LOGLEVEL_OPERATOR);
200 /** Numeric postfix increment. Returns the number and leaves the original
201 * incremented by 1. */
202 numeric operator++(numeric & lh, int)
204 debugmsg("operator++(numeric,int)",LOGLEVEL_OPERATOR);
210 /** Numeric Postfix decrement. Returns the number and leaves the original
211 * decremented by 1. */
212 numeric operator--(numeric & lh, int)
214 debugmsg("operator--(numeric,int)",LOGLEVEL_OPERATOR);
220 // binary relational operators ex with ex
222 relational operator==(const ex & lh, const ex & rh)
224 debugmsg("operator==(ex,ex)",LOGLEVEL_OPERATOR);
225 return relational(lh,rh,relational::equal);
228 relational operator!=(const ex & lh, const ex & rh)
230 debugmsg("operator!=(ex,ex)",LOGLEVEL_OPERATOR);
231 return relational(lh,rh,relational::not_equal);
234 relational operator<(const ex & lh, const ex & rh)
236 debugmsg("operator<(ex,ex)",LOGLEVEL_OPERATOR);
237 return relational(lh,rh,relational::less);
240 relational operator<=(const ex & lh, const ex & rh)
242 debugmsg("operator<=(ex,ex)",LOGLEVEL_OPERATOR);
243 return relational(lh,rh,relational::less_or_equal);
246 relational operator>(const ex & lh, const ex & rh)
248 debugmsg("operator>(ex,ex)",LOGLEVEL_OPERATOR);
249 return relational(lh,rh,relational::greater);
252 relational operator>=(const ex & lh, const ex & rh)
254 debugmsg("operator>=(ex,ex)",LOGLEVEL_OPERATOR);
255 return relational(lh,rh,relational::greater_or_equal);
258 // input/output stream operators
260 std::ostream & operator<<(std::ostream & os, const ex & e)
266 std::istream & operator>>(std::istream & is, ex & e)
268 throw (std::logic_error("expression input from streams not implemented"));
271 #ifndef NO_NAMESPACE_GINAC
273 #endif // ndef NO_NAMESPACE_GINAC