1 /** @file operators.cpp
3 * Implementation of GiNaC's overloaded operators. */
10 // binary arithmetic operators ex with ex
12 ex operator+(ex const & lh, ex const & rh)
14 debugmsg("operator+(ex,ex)",LOGLEVEL_OPERATOR);
18 ex operator-(ex const & lh, ex const & rh)
20 debugmsg("operator-(ex,ex)",LOGLEVEL_OPERATOR);
21 return lh.exadd(rh.exmul(exMINUSONE()));
24 ex operator*(ex const & lh, ex const & rh)
26 debugmsg("operator*(ex,ex)",LOGLEVEL_OPERATOR);
30 ex operator/(ex const & lh, ex const & rh)
32 debugmsg("operator*(ex,ex)",LOGLEVEL_OPERATOR);
33 return lh.exmul(power(rh,exMINUSONE()));
36 ex operator%(ex const & lh, ex const & rh)
38 debugmsg("operator%(ex,ex)",LOGLEVEL_OPERATOR);
39 return lh.exncmul(rh);
44 // binary arithmetic operators ex with numeric
46 ex operator+(ex const & lh, numeric const & rh)
48 debugmsg("operator+(ex,numeric)",LOGLEVEL_OPERATOR);
52 ex operator-(ex const & lh, numeric const & rh)
54 debugmsg("operator-(ex,numeric)",LOGLEVEL_OPERATOR);
58 ex operator*(ex const & lh, numeric const & rh)
60 debugmsg("operator*(ex,numeric)",LOGLEVEL_OPERATOR);
64 ex operator/(ex const & lh, numeric const & rh)
66 debugmsg("operator/(ex,numeric)",LOGLEVEL_OPERATOR);
70 ex operator%(ex const & lh, numeric const & rh)
72 debugmsg("operator%(ex,numeric)",LOGLEVEL_OPERATOR);
76 // binary arithmetic operators numeric with ex
78 ex operator+(numeric const & lh, ex const & rh)
80 debugmsg("operator+(numeric,ex)",LOGLEVEL_OPERATOR);
84 ex operator-(numeric const & lh, ex const & rh)
86 debugmsg("operator-(numeric,ex)",LOGLEVEL_OPERATOR);
90 ex operator*(numeric const & lh, ex const & rh)
92 debugmsg("operator*(numeric,ex)",LOGLEVEL_OPERATOR);
96 ex operator/(numeric const & lh, ex const & rh)
98 debugmsg("operator/(numeric,ex)",LOGLEVEL_OPERATOR);
102 ex operator%(numeric const & lh, ex const & rh)
104 debugmsg("operator%(numeric,ex)",LOGLEVEL_OPERATOR);
110 // binary arithmetic operators numeric with numeric
112 numeric operator+(numeric const & lh, numeric const & rh)
114 debugmsg("operator+(numeric,numeric)",LOGLEVEL_OPERATOR);
118 numeric operator-(numeric const & lh, numeric const & rh)
120 debugmsg("operator-(numeric,numeric)",LOGLEVEL_OPERATOR);
124 numeric operator*(numeric const & lh, numeric const & rh)
126 debugmsg("operator*(numeric,numeric)",LOGLEVEL_OPERATOR);
130 numeric operator/(numeric const & lh, numeric const & rh)
132 debugmsg("operator/(numeric,ex)",LOGLEVEL_OPERATOR);
136 // binary arithmetic assignment operators with ex
138 ex const & operator+=(ex & lh, ex const & rh)
140 debugmsg("operator+=(ex,ex)",LOGLEVEL_OPERATOR);
144 ex const & operator-=(ex & lh, ex const & rh)
146 debugmsg("operator-=(ex,ex)",LOGLEVEL_OPERATOR);
150 ex const & operator*=(ex & lh, ex const & rh)
152 debugmsg("operator*=(ex,ex)",LOGLEVEL_OPERATOR);
156 ex const & operator/=(ex & lh, ex const & rh)
158 debugmsg("operator/=(ex,ex)",LOGLEVEL_OPERATOR);
162 ex const & operator%=(ex & lh, ex const & rh)
164 debugmsg("operator%=(ex,ex)",LOGLEVEL_OPERATOR);
170 // binary arithmetic assignment operators with numeric
172 ex const & operator+=(ex & lh, numeric const & rh)
174 debugmsg("operator+=(ex,numeric)",LOGLEVEL_OPERATOR);
175 return (lh=lh+ex(rh));
178 ex const & operator-=(ex & lh, numeric const & rh)
180 debugmsg("operator-=(ex,numeric)",LOGLEVEL_OPERATOR);
181 return (lh=lh-ex(rh));
184 ex const & operator*=(ex & lh, numeric const & rh)
186 debugmsg("operator*=(ex,numeric)",LOGLEVEL_OPERATOR);
187 return (lh=lh*ex(rh));
190 ex const & operator/=(ex & lh, numeric const & rh)
192 debugmsg("operator/=(ex,numeric)",LOGLEVEL_OPERATOR);
193 return (lh=lh/ex(rh));
196 ex const & operator%=(ex & lh, numeric const & rh)
198 debugmsg("operator%=(ex,numeric)",LOGLEVEL_OPERATOR);
199 return (lh=lh%ex(rh));
204 // binary arithmetic assignment operators with numeric
206 numeric const & operator+=(numeric & lh, numeric const & rh)
208 debugmsg("operator+=(numeric,numeric)",LOGLEVEL_OPERATOR);
209 return (lh=lh.add(rh));
212 numeric const & operator-=(numeric & lh, numeric const & rh)
214 debugmsg("operator-=(numeric,numeric)",LOGLEVEL_OPERATOR);
215 return (lh=lh.sub(rh));
218 numeric const & operator*=(numeric & lh, numeric const & rh)
220 debugmsg("operator*=(numeric,numeric)",LOGLEVEL_OPERATOR);
221 return (lh=lh.mul(rh));
224 numeric const & operator/=(numeric & lh, numeric const & rh)
226 debugmsg("operator/=(numeric,numeric)",LOGLEVEL_OPERATOR);
227 return (lh=lh.div(rh));
232 ex operator+(ex const & lh)
237 ex operator-(ex const & lh)
239 return exMINUSONE()*lh;
242 numeric operator+(numeric const & lh)
247 numeric operator-(numeric const & lh)
249 return (numeric(-1)*lh);
252 // binary relational operators ex with ex
254 relational operator==(ex const & lh, ex const & rh)
256 debugmsg("operator==(ex,ex)",LOGLEVEL_OPERATOR);
257 return relational(lh,rh,relational::equal);
260 relational operator!=(ex const & lh, ex const & rh)
262 debugmsg("operator!=(ex,ex)",LOGLEVEL_OPERATOR);
263 return relational(lh,rh,relational::not_equal);
266 relational operator<(ex const & lh, ex const & rh)
268 debugmsg("operator<(ex,ex)",LOGLEVEL_OPERATOR);
269 return relational(lh,rh,relational::less);
272 relational operator<=(ex const & lh, ex const & rh)
274 debugmsg("operator<=(ex,ex)",LOGLEVEL_OPERATOR);
275 return relational(lh,rh,relational::less_or_equal);
278 relational operator>(ex const & lh, ex const & rh)
280 debugmsg("operator>(ex,ex)",LOGLEVEL_OPERATOR);
281 return relational(lh,rh,relational::greater);
284 relational operator>=(ex const & lh, ex const & rh)
286 debugmsg("operator>=(ex,ex)",LOGLEVEL_OPERATOR);
287 return relational(lh,rh,relational::greater_or_equal);
292 // binary relational operators ex with numeric
294 relational operator==(ex const & lh, numeric const & rh)
296 debugmsg("operator==(ex,numeric)",LOGLEVEL_OPERATOR);
297 return relational(lh,rh,relational::equal);
300 relational operator!=(ex const & lh, numeric const & rh)
302 debugmsg("operator!=(ex,numeric)",LOGLEVEL_OPERATOR);
303 return relational(lh,rh,relational::not_equal);
306 relational operator<(ex const & lh, numeric const & rh)
308 debugmsg("operator<(ex,numeric)",LOGLEVEL_OPERATOR);
309 return relational(lh,rh,relational::less);
312 relational operator<=(ex const & lh, numeric const & rh)
314 debugmsg("operator<=(ex,numeric)",LOGLEVEL_OPERATOR);
315 return relational(lh,rh,relational::less_or_equal);
318 relational operator>(ex const & lh, numeric const & rh)
320 debugmsg("operator>(ex,numeric)",LOGLEVEL_OPERATOR);
321 return relational(lh,rh,relational::greater);
324 relational operator>=(ex const & lh, numeric const & rh)
326 debugmsg("operator>=(ex,numeric)",LOGLEVEL_OPERATOR);
327 return relational(lh,rh,relational::greater_or_equal);
330 // binary relational operators numeric with ex
332 relational operator==(numeric const & lh, ex const & rh)
334 debugmsg("operator==(numeric,ex)",LOGLEVEL_OPERATOR);
335 return relational(lh,rh,relational::equal);
338 relational operator!=(numeric const & lh, ex const & rh)
340 debugmsg("operator!=(numeric,ex)",LOGLEVEL_OPERATOR);
341 return relational(lh,rh,relational::not_equal);
344 relational operator<(numeric const & lh, ex const & rh)
346 debugmsg("operator<(numeric,ex)",LOGLEVEL_OPERATOR);
347 return relational(lh,rh,relational::less);
350 relational operator<=(numeric const & lh, ex const & rh)
352 debugmsg("operator<=(numeric,ex)",LOGLEVEL_OPERATOR);
353 return relational(lh,rh,relational::less_or_equal);
356 relational operator>(numeric const & lh, ex const & rh)
358 debugmsg("operator>(numeric,ex)",LOGLEVEL_OPERATOR);
359 return relational(lh,rh,relational::greater);
362 relational operator>=(numeric const & lh, ex const & rh)
364 debugmsg("operator>=(numeric,ex)",LOGLEVEL_OPERATOR);
365 return relational(lh,rh,relational::greater_or_equal);
370 // input/output stream operators
372 ostream & operator<<(ostream & os, ex const & e)
378 istream & operator>>(istream & is, ex & e)
380 throw(std::logic_error("input from streams not yet implemented"));