1 /** @file operators.cpp
3 * Implementation of GiNaC's overloaded operators. */
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
26 #include "operators.h"
31 #include "relational.h"
35 #ifndef NO_GINAC_NAMESPACE
37 #endif // ndef NO_GINAC_NAMESPACE
39 // binary arithmetic operators ex with ex
41 ex operator+(ex const & lh, ex const & rh)
43 debugmsg("operator+(ex,ex)",LOGLEVEL_OPERATOR);
47 ex operator-(ex const & lh, ex const & rh)
49 debugmsg("operator-(ex,ex)",LOGLEVEL_OPERATOR);
50 return lh.exadd(rh.exmul(_ex_1()));
53 ex operator*(ex const & lh, ex const & rh)
55 debugmsg("operator*(ex,ex)",LOGLEVEL_OPERATOR);
59 ex operator/(ex const & lh, ex const & rh)
61 debugmsg("operator*(ex,ex)",LOGLEVEL_OPERATOR);
62 return lh.exmul(power(rh,_ex_1()));
65 ex operator%(ex const & lh, ex const & rh)
67 debugmsg("operator%(ex,ex)",LOGLEVEL_OPERATOR);
68 return lh.exncmul(rh);
72 // binary arithmetic operators numeric with numeric
74 numeric operator+(numeric const & lh, numeric const & rh)
76 debugmsg("operator+(numeric,numeric)",LOGLEVEL_OPERATOR);
80 numeric operator-(numeric const & lh, numeric const & rh)
82 debugmsg("operator-(numeric,numeric)",LOGLEVEL_OPERATOR);
86 numeric operator*(numeric const & lh, numeric const & rh)
88 debugmsg("operator*(numeric,numeric)",LOGLEVEL_OPERATOR);
92 numeric operator/(numeric const & lh, numeric const & rh)
94 debugmsg("operator/(numeric,ex)",LOGLEVEL_OPERATOR);
99 // binary arithmetic assignment operators with ex
101 ex const & operator+=(ex & lh, ex const & rh)
103 debugmsg("operator+=(ex,ex)",LOGLEVEL_OPERATOR);
107 ex const & operator-=(ex & lh, ex const & rh)
109 debugmsg("operator-=(ex,ex)",LOGLEVEL_OPERATOR);
113 ex const & operator*=(ex & lh, ex const & rh)
115 debugmsg("operator*=(ex,ex)",LOGLEVEL_OPERATOR);
119 ex const & operator/=(ex & lh, ex const & rh)
121 debugmsg("operator/=(ex,ex)",LOGLEVEL_OPERATOR);
125 ex const & operator%=(ex & lh, ex const & rh)
127 debugmsg("operator%=(ex,ex)",LOGLEVEL_OPERATOR);
132 // binary arithmetic assignment operators with numeric
134 numeric const & operator+=(numeric & lh, numeric const & rh)
136 debugmsg("operator+=(numeric,numeric)",LOGLEVEL_OPERATOR);
137 return (lh=lh.add(rh));
140 numeric const & operator-=(numeric & lh, numeric const & rh)
142 debugmsg("operator-=(numeric,numeric)",LOGLEVEL_OPERATOR);
143 return (lh=lh.sub(rh));
146 numeric const & operator*=(numeric & lh, numeric const & rh)
148 debugmsg("operator*=(numeric,numeric)",LOGLEVEL_OPERATOR);
149 return (lh=lh.mul(rh));
152 numeric const & operator/=(numeric & lh, numeric const & rh)
154 debugmsg("operator/=(numeric,numeric)",LOGLEVEL_OPERATOR);
155 return (lh=lh.div(rh));
160 ex operator+(ex const & lh)
165 ex operator-(ex const & lh)
167 return lh.exmul(_ex_1());
170 numeric operator+(numeric const & lh)
175 numeric operator-(numeric const & lh)
180 /** Numeric prefix increment. Adds 1 and returns incremented number. */
181 numeric& operator++(numeric & rh)
187 /** Numeric prefix decrement. Subtracts 1 and returns decremented number. */
188 numeric& operator--(numeric & rh)
194 /** Numeric postfix increment. Returns the number and leaves the original
195 * incremented by 1. */
196 numeric operator++(numeric & lh, int)
203 /** Numeric Postfix decrement. Returns the number and leaves the original
204 * decremented by 1. */
205 numeric operator--(numeric & lh, int)
212 // binary relational operators ex with ex
214 relational operator==(ex const & lh, ex const & rh)
216 debugmsg("operator==(ex,ex)",LOGLEVEL_OPERATOR);
217 return relational(lh,rh,relational::equal);
220 relational operator!=(ex const & lh, ex const & rh)
222 debugmsg("operator!=(ex,ex)",LOGLEVEL_OPERATOR);
223 return relational(lh,rh,relational::not_equal);
226 relational operator<(ex const & lh, ex const & rh)
228 debugmsg("operator<(ex,ex)",LOGLEVEL_OPERATOR);
229 return relational(lh,rh,relational::less);
232 relational operator<=(ex const & lh, ex const & rh)
234 debugmsg("operator<=(ex,ex)",LOGLEVEL_OPERATOR);
235 return relational(lh,rh,relational::less_or_equal);
238 relational operator>(ex const & lh, ex const & rh)
240 debugmsg("operator>(ex,ex)",LOGLEVEL_OPERATOR);
241 return relational(lh,rh,relational::greater);
244 relational operator>=(ex const & lh, ex const & rh)
246 debugmsg("operator>=(ex,ex)",LOGLEVEL_OPERATOR);
247 return relational(lh,rh,relational::greater_or_equal);
252 // binary relational operators ex with numeric
254 relational operator==(ex const & lh, numeric const & rh)
256 debugmsg("operator==(ex,numeric)",LOGLEVEL_OPERATOR);
257 return relational(lh,rh,relational::equal);
260 relational operator!=(ex const & lh, numeric const & rh)
262 debugmsg("operator!=(ex,numeric)",LOGLEVEL_OPERATOR);
263 return relational(lh,rh,relational::not_equal);
266 relational operator<(ex const & lh, numeric const & rh)
268 debugmsg("operator<(ex,numeric)",LOGLEVEL_OPERATOR);
269 return relational(lh,rh,relational::less);
272 relational operator<=(ex const & lh, numeric const & rh)
274 debugmsg("operator<=(ex,numeric)",LOGLEVEL_OPERATOR);
275 return relational(lh,rh,relational::less_or_equal);
278 relational operator>(ex const & lh, numeric const & rh)
280 debugmsg("operator>(ex,numeric)",LOGLEVEL_OPERATOR);
281 return relational(lh,rh,relational::greater);
284 relational operator>=(ex const & lh, numeric const & rh)
286 debugmsg("operator>=(ex,numeric)",LOGLEVEL_OPERATOR);
287 return relational(lh,rh,relational::greater_or_equal);
290 // binary relational operators numeric with ex
292 relational operator==(numeric const & lh, ex const & rh)
294 debugmsg("operator==(numeric,ex)",LOGLEVEL_OPERATOR);
295 return relational(lh,rh,relational::equal);
298 relational operator!=(numeric const & lh, ex const & rh)
300 debugmsg("operator!=(numeric,ex)",LOGLEVEL_OPERATOR);
301 return relational(lh,rh,relational::not_equal);
304 relational operator<(numeric const & lh, ex const & rh)
306 debugmsg("operator<(numeric,ex)",LOGLEVEL_OPERATOR);
307 return relational(lh,rh,relational::less);
310 relational operator<=(numeric const & lh, ex const & rh)
312 debugmsg("operator<=(numeric,ex)",LOGLEVEL_OPERATOR);
313 return relational(lh,rh,relational::less_or_equal);
316 relational operator>(numeric const & lh, ex const & rh)
318 debugmsg("operator>(numeric,ex)",LOGLEVEL_OPERATOR);
319 return relational(lh,rh,relational::greater);
322 relational operator>=(numeric const & lh, ex const & rh)
324 debugmsg("operator>=(numeric,ex)",LOGLEVEL_OPERATOR);
325 return relational(lh,rh,relational::greater_or_equal);
330 // input/output stream operators
332 ostream & operator<<(ostream & os, ex const & e)
338 istream & operator>>(istream & is, ex & e)
340 throw(std::logic_error("input from streams not yet implemented"));
343 #ifndef NO_GINAC_NAMESPACE
345 #endif // ndef NO_GINAC_NAMESPACE