]> www.ginac.de Git - ginac.git/blobdiff - ginac/operators.cpp
* Methods of class ex which do absolutely nothing than type dispatch should
[ginac.git] / ginac / operators.cpp
index 506f47b7a77e9d9b9072c4fca09e1e4683908f4f..ee240174f6ad0f5cac9a5daee41d69316e0ecb29 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's overloaded operators. */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2001 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
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <iostream>
-#include <stdexcept>
-
 #include "operators.h"
-#include "basic.h"
-#include "ex.h"
 #include "numeric.h"
 #include "power.h"
 #include "relational.h"
+#include "print.h"
 #include "debugmsg.h"
 #include "utils.h"
 
-#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
 
 // binary arithmetic operators ex with ex
 
@@ -62,12 +56,6 @@ ex operator/(const ex & lh, const ex & rh)
        return lh.exmul(power(rh,_ex_1()));
 }
 
-ex operator%(const ex & lh, const ex & rh)
-{
-       debugmsg("operator%(ex,ex)",LOGLEVEL_OPERATOR);
-       return lh.exncmul(rh);
-}
-
 
 // binary arithmetic operators numeric with numeric
 
@@ -101,31 +89,25 @@ numeric operator/(const numeric & lh, const numeric & rh)
 const ex & operator+=(ex & lh, const ex & rh)
 {
        debugmsg("operator+=(ex,ex)",LOGLEVEL_OPERATOR);
-       return (lh=lh+rh);
+       return (lh=lh.exadd(rh));
 }
 
 const ex & operator-=(ex & lh, const ex & rh)
 {
        debugmsg("operator-=(ex,ex)",LOGLEVEL_OPERATOR);
-       return (lh=lh-rh);
+       return (lh=lh.exadd(rh.exmul(_ex_1())));
 }
 
 const ex & operator*=(ex & lh, const ex & rh)
 {
        debugmsg("operator*=(ex,ex)",LOGLEVEL_OPERATOR);
-       return (lh=lh*rh);
+       return (lh=lh.exmul(rh));
 }
 
 const ex & operator/=(ex & lh, const ex & rh)
 {
        debugmsg("operator/=(ex,ex)",LOGLEVEL_OPERATOR);
-       return (lh=lh/rh);
-}
-
-const ex & operator%=(ex & lh, const ex & rh)
-{
-       debugmsg("operator%=(ex,ex)",LOGLEVEL_OPERATOR);
-       return (lh=lh%rh);
+       return (lh=lh.exmul(power(rh,_ex_1())));
 }
 
 
@@ -178,14 +160,14 @@ numeric operator+(const numeric & lh)
 numeric operator-(const numeric & lh)
 {
        debugmsg("operator-(numeric)",LOGLEVEL_OPERATOR);
-       return _num_1()*lh;
+       return _num_1().mul(lh);
 }
 
 /** Numeric prefix increment.  Adds 1 and returns incremented number. */
 numeric& operator++(numeric & rh)
 {
        debugmsg("operator++(numeric)",LOGLEVEL_OPERATOR);
-       rh = rh+_num1();
+       rh = rh.add(_num1());
        return rh;
 }
 
@@ -193,7 +175,7 @@ numeric& operator++(numeric & rh)
 numeric& operator--(numeric & rh)
 {
        debugmsg("operator--(numeric)",LOGLEVEL_OPERATOR);
-       rh = rh-_num1();
+       rh = rh.add(_num_1());
        return rh;
 }
 
@@ -202,8 +184,8 @@ numeric& operator--(numeric & rh)
 numeric operator++(numeric & lh, int)
 {
        debugmsg("operator++(numeric,int)",LOGLEVEL_OPERATOR);
-       numeric tmp = lh;
-       lh = lh+_num1();
+       numeric tmp(lh);
+       lh = lh.add(_num1());
        return tmp;
 }
 
@@ -212,8 +194,8 @@ numeric operator++(numeric & lh, int)
 numeric operator--(numeric & lh, int)
 {
        debugmsg("operator--(numeric,int)",LOGLEVEL_OPERATOR);
-       numeric tmp = lh;
-       lh = lh-_num1();
+       numeric tmp(lh);
+       lh = lh.add(_num_1());
        return tmp;
 }
 
@@ -259,7 +241,7 @@ relational operator>=(const ex & lh, const ex & rh)
 
 std::ostream & operator<<(std::ostream & os, const ex & e)
 {
-       e.print(os);
+       e.print(print_context(os));
        return os;
 }
 
@@ -268,6 +250,4 @@ std::istream & operator>>(std::istream & is, ex & e)
        throw (std::logic_error("expression input from streams not implemented"));
 }
 
-#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_NAMESPACE_GINAC