X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Foperators.cpp;h=9a681b5ea2e2e68f263e40caad0c3956af4cc476;hp=4d762b305c2424ccb623ad5a6e11a61bfa65681e;hb=601880914ba5553a1fea9f36491060b15db1ba2c;hpb=48b41ea321ed9fa6115a1061d1a1d2f8d8ad0400 diff --git a/ginac/operators.cpp b/ginac/operators.cpp index 4d762b30..9a681b5e 100644 --- a/ginac/operators.cpp +++ b/ginac/operators.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's overloaded operators. */ /* - * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,224 +30,126 @@ #include "power.h" #include "relational.h" #include "debugmsg.h" +#include "utils.h" +#ifndef NO_NAMESPACE_GINAC namespace GiNaC { +#endif // ndef NO_NAMESPACE_GINAC // binary arithmetic operators ex with ex -ex operator+(ex const & lh, ex const & rh) +ex operator+(const ex & lh, const ex & rh) { debugmsg("operator+(ex,ex)",LOGLEVEL_OPERATOR); return lh.exadd(rh); } -ex operator-(ex const & lh, ex const & rh) +ex operator-(const ex & lh, const ex & rh) { debugmsg("operator-(ex,ex)",LOGLEVEL_OPERATOR); - return lh.exadd(rh.exmul(exMINUSONE())); + return lh.exadd(rh.exmul(_ex_1())); } -ex operator*(ex const & lh, ex const & rh) +ex operator*(const ex & lh, const ex & rh) { debugmsg("operator*(ex,ex)",LOGLEVEL_OPERATOR); return lh.exmul(rh); } -ex operator/(ex const & lh, ex const & rh) +ex operator/(const ex & lh, const ex & rh) { debugmsg("operator*(ex,ex)",LOGLEVEL_OPERATOR); - return lh.exmul(power(rh,exMINUSONE())); + return lh.exmul(power(rh,_ex_1())); } -ex operator%(ex const & lh, ex const & rh) +ex operator%(const ex & lh, const ex & rh) { debugmsg("operator%(ex,ex)",LOGLEVEL_OPERATOR); return lh.exncmul(rh); } -/* - -// binary arithmetic operators ex with numeric - -ex operator+(ex const & lh, numeric const & rh) -{ - debugmsg("operator+(ex,numeric)",LOGLEVEL_OPERATOR); - return lh+ex(rh); -} - -ex operator-(ex const & lh, numeric const & rh) -{ - debugmsg("operator-(ex,numeric)",LOGLEVEL_OPERATOR); - return lh-ex(rh); -} - -ex operator*(ex const & lh, numeric const & rh) -{ - debugmsg("operator*(ex,numeric)",LOGLEVEL_OPERATOR); - return lh*ex(rh); -} - -ex operator/(ex const & lh, numeric const & rh) -{ - debugmsg("operator/(ex,numeric)",LOGLEVEL_OPERATOR); - return lh/ex(rh); -} - -ex operator%(ex const & lh, numeric const & rh) -{ - debugmsg("operator%(ex,numeric)",LOGLEVEL_OPERATOR); - return lh%ex(rh); -} - -// binary arithmetic operators numeric with ex - -ex operator+(numeric const & lh, ex const & rh) -{ - debugmsg("operator+(numeric,ex)",LOGLEVEL_OPERATOR); - return ex(lh)+rh; -} - -ex operator-(numeric const & lh, ex const & rh) -{ - debugmsg("operator-(numeric,ex)",LOGLEVEL_OPERATOR); - return ex(lh)-rh; -} - -ex operator*(numeric const & lh, ex const & rh) -{ - debugmsg("operator*(numeric,ex)",LOGLEVEL_OPERATOR); - return ex(lh)*rh; -} - -ex operator/(numeric const & lh, ex const & rh) -{ - debugmsg("operator/(numeric,ex)",LOGLEVEL_OPERATOR); - return ex(lh)/rh; -} - -ex operator%(numeric const & lh, ex const & rh) -{ - debugmsg("operator%(numeric,ex)",LOGLEVEL_OPERATOR); - return ex(lh)%rh; -} - -*/ // binary arithmetic operators numeric with numeric -numeric operator+(numeric const & lh, numeric const & rh) +numeric operator+(const numeric & lh, const numeric & rh) { debugmsg("operator+(numeric,numeric)",LOGLEVEL_OPERATOR); return lh.add(rh); } -numeric operator-(numeric const & lh, numeric const & rh) +numeric operator-(const numeric & lh, const numeric & rh) { debugmsg("operator-(numeric,numeric)",LOGLEVEL_OPERATOR); return lh.sub(rh); } -numeric operator*(numeric const & lh, numeric const & rh) +numeric operator*(const numeric & lh, const numeric & rh) { debugmsg("operator*(numeric,numeric)",LOGLEVEL_OPERATOR); return lh.mul(rh); } -numeric operator/(numeric const & lh, numeric const & rh) +numeric operator/(const numeric & lh, const numeric & rh) { debugmsg("operator/(numeric,ex)",LOGLEVEL_OPERATOR); return lh.div(rh); } + // binary arithmetic assignment operators with ex -ex const & operator+=(ex & lh, ex const & rh) +const ex & operator+=(ex & lh, const ex & rh) { debugmsg("operator+=(ex,ex)",LOGLEVEL_OPERATOR); return (lh=lh+rh); } -ex const & operator-=(ex & lh, ex const & rh) +const ex & operator-=(ex & lh, const ex & rh) { debugmsg("operator-=(ex,ex)",LOGLEVEL_OPERATOR); return (lh=lh-rh); } -ex const & operator*=(ex & lh, ex const & rh) +const ex & operator*=(ex & lh, const ex & rh) { debugmsg("operator*=(ex,ex)",LOGLEVEL_OPERATOR); return (lh=lh*rh); } -ex const & operator/=(ex & lh, ex const & rh) +const ex & operator/=(ex & lh, const ex & rh) { debugmsg("operator/=(ex,ex)",LOGLEVEL_OPERATOR); return (lh=lh/rh); } -ex const & operator%=(ex & lh, ex const & rh) +const ex & operator%=(ex & lh, const ex & rh) { debugmsg("operator%=(ex,ex)",LOGLEVEL_OPERATOR); return (lh=lh%rh); } -/* - -// binary arithmetic assignment operators with numeric - -ex const & operator+=(ex & lh, numeric const & rh) -{ - debugmsg("operator+=(ex,numeric)",LOGLEVEL_OPERATOR); - return (lh=lh+ex(rh)); -} - -ex const & operator-=(ex & lh, numeric const & rh) -{ - debugmsg("operator-=(ex,numeric)",LOGLEVEL_OPERATOR); - return (lh=lh-ex(rh)); -} - -ex const & operator*=(ex & lh, numeric const & rh) -{ - debugmsg("operator*=(ex,numeric)",LOGLEVEL_OPERATOR); - return (lh=lh*ex(rh)); -} - -ex const & operator/=(ex & lh, numeric const & rh) -{ - debugmsg("operator/=(ex,numeric)",LOGLEVEL_OPERATOR); - return (lh=lh/ex(rh)); -} - -ex const & operator%=(ex & lh, numeric const & rh) -{ - debugmsg("operator%=(ex,numeric)",LOGLEVEL_OPERATOR); - return (lh=lh%ex(rh)); -} - -*/ // binary arithmetic assignment operators with numeric -numeric const & operator+=(numeric & lh, numeric const & rh) +const numeric & operator+=(numeric & lh, const numeric & rh) { debugmsg("operator+=(numeric,numeric)",LOGLEVEL_OPERATOR); return (lh=lh.add(rh)); } -numeric const & operator-=(numeric & lh, numeric const & rh) +const numeric & operator-=(numeric & lh, const numeric & rh) { debugmsg("operator-=(numeric,numeric)",LOGLEVEL_OPERATOR); return (lh=lh.sub(rh)); } -numeric const & operator*=(numeric & lh, numeric const & rh) +const numeric & operator*=(numeric & lh, const numeric & rh) { debugmsg("operator*=(numeric,numeric)",LOGLEVEL_OPERATOR); return (lh=lh.mul(rh)); } -numeric const & operator/=(numeric & lh, numeric const & rh) +const numeric & operator/=(numeric & lh, const numeric & rh) { debugmsg("operator/=(numeric,numeric)",LOGLEVEL_OPERATOR); return (lh=lh.div(rh)); @@ -255,37 +157,37 @@ numeric const & operator/=(numeric & lh, numeric const & rh) // unary operators -ex operator+(ex const & lh) +ex operator+(const ex & lh) { return lh; } -ex operator-(ex const & lh) +ex operator-(const ex & lh) { - return exMINUSONE()*lh; + return lh.exmul(_ex_1()); } -numeric operator+(numeric const & lh) +numeric operator+(const numeric & lh) { return lh; } -numeric operator-(numeric const & lh) +numeric operator-(const numeric & lh) { - return numMINUSONE()*lh; + return _num_1()*lh; } /** Numeric prefix increment. Adds 1 and returns incremented number. */ numeric& operator++(numeric & rh) { - rh = rh+numONE(); + rh = rh+_num1(); return rh; } /** Numeric prefix decrement. Subtracts 1 and returns decremented number. */ numeric& operator--(numeric & rh) { - rh = rh-numONE(); + rh = rh-_num1(); return rh; } @@ -294,7 +196,7 @@ numeric& operator--(numeric & rh) numeric operator++(numeric & lh, int) { numeric tmp = lh; - lh = lh+numONE(); + lh = lh+_num1(); return tmp; } @@ -303,43 +205,43 @@ numeric operator++(numeric & lh, int) numeric operator--(numeric & lh, int) { numeric tmp = lh; - lh = lh-numONE(); + lh = lh-_num1(); return tmp; } // binary relational operators ex with ex -relational operator==(ex const & lh, ex const & rh) +relational operator==(const ex & lh, const ex & rh) { debugmsg("operator==(ex,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::equal); } -relational operator!=(ex const & lh, ex const & rh) +relational operator!=(const ex & lh, const ex & rh) { debugmsg("operator!=(ex,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::not_equal); } -relational operator<(ex const & lh, ex const & rh) +relational operator<(const ex & lh, const ex & rh) { debugmsg("operator<(ex,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::less); } -relational operator<=(ex const & lh, ex const & rh) +relational operator<=(const ex & lh, const ex & rh) { debugmsg("operator<=(ex,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::less_or_equal); } -relational operator>(ex const & lh, ex const & rh) +relational operator>(const ex & lh, const ex & rh) { debugmsg("operator>(ex,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::greater); } -relational operator>=(ex const & lh, ex const & rh) +relational operator>=(const ex & lh, const ex & rh) { debugmsg("operator>=(ex,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::greater_or_equal); @@ -349,37 +251,37 @@ relational operator>=(ex const & lh, ex const & rh) // binary relational operators ex with numeric -relational operator==(ex const & lh, numeric const & rh) +relational operator==(const ex & lh, const numeric & rh) { debugmsg("operator==(ex,numeric)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::equal); } -relational operator!=(ex const & lh, numeric const & rh) +relational operator!=(const ex & lh, const numeric & rh) { debugmsg("operator!=(ex,numeric)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::not_equal); } -relational operator<(ex const & lh, numeric const & rh) +relational operator<(const ex & lh, const numeric & rh) { debugmsg("operator<(ex,numeric)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::less); } -relational operator<=(ex const & lh, numeric const & rh) +relational operator<=(const ex & lh, const numeric & rh) { debugmsg("operator<=(ex,numeric)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::less_or_equal); } -relational operator>(ex const & lh, numeric const & rh) +relational operator>(const ex & lh, const numeric & rh) { debugmsg("operator>(ex,numeric)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::greater); } -relational operator>=(ex const & lh, numeric const & rh) +relational operator>=(const ex & lh, const numeric & rh) { debugmsg("operator>=(ex,numeric)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::greater_or_equal); @@ -387,37 +289,37 @@ relational operator>=(ex const & lh, numeric const & rh) // binary relational operators numeric with ex -relational operator==(numeric const & lh, ex const & rh) +relational operator==(const numeric & lh, const ex & rh) { debugmsg("operator==(numeric,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::equal); } -relational operator!=(numeric const & lh, ex const & rh) +relational operator!=(const numeric & lh, const ex & rh) { debugmsg("operator!=(numeric,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::not_equal); } -relational operator<(numeric const & lh, ex const & rh) +relational operator<(const numeric & lh, const ex & rh) { debugmsg("operator<(numeric,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::less); } -relational operator<=(numeric const & lh, ex const & rh) +relational operator<=(const numeric & lh, const ex & rh) { debugmsg("operator<=(numeric,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::less_or_equal); } -relational operator>(numeric const & lh, ex const & rh) +relational operator>(const numeric & lh, const ex & rh) { debugmsg("operator>(numeric,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::greater); } -relational operator>=(numeric const & lh, ex const & rh) +relational operator>=(const numeric & lh, const ex & rh) { debugmsg("operator>=(numeric,ex)",LOGLEVEL_OPERATOR); return relational(lh,rh,relational::greater_or_equal); @@ -427,7 +329,7 @@ relational operator>=(numeric const & lh, ex const & rh) // input/output stream operators -ostream & operator<<(ostream & os, ex const & e) +ostream & operator<<(ostream & os, const ex & e) { e.print(os); return os; @@ -438,4 +340,6 @@ istream & operator>>(istream & is, ex & e) throw(std::logic_error("input from streams not yet implemented")); } +#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC +#endif // ndef NO_NAMESPACE_GINAC