]> www.ginac.de Git - ginac.git/blobdiff - ginac/print.cpp
- changed mul::print() to behave similar to add::print()
[ginac.git] / ginac / print.cpp
index 1df9cd2fbe1387e3c02ba65b392018a207780e08..f90a40ce89fa86aa9acb01e3ca15bd37ff70ad47 100644 (file)
@@ -146,7 +146,8 @@ void add::print(ostream & os, unsigned upper_precedence) const
             if (coeff.csgn()==-1) os << '-';
             first=false;
         }
             if (coeff.csgn()==-1) os << '-';
             first=false;
         }
-        if (coeff.compare(numONE()) && coeff.compare(numMINUSONE())) {
+        if (!coeff.is_equal(numONE()) &&
+            !coeff.is_equal(numMINUSONE())) {
             if (coeff.csgn()==-1)
                 (numMINUSONE()*coeff).print(os, precedence);
             else
             if (coeff.csgn()==-1)
                 (numMINUSONE()*coeff).print(os, precedence);
             else
@@ -168,10 +169,17 @@ void mul::print(ostream & os, unsigned upper_precedence) const
     debugmsg("mul print",LOGLEVEL_PRINT);
     if (precedence<=upper_precedence) os << "(";
     bool first=true;
     debugmsg("mul print",LOGLEVEL_PRINT);
     if (precedence<=upper_precedence) os << "(";
     bool first=true;
-    if (!overall_coeff.is_equal(exONE())) {
-        overall_coeff.print(os,precedence);
-        first=false;
+    // first print the overall numeric coefficient:
+    if (ex_to_numeric(overall_coeff).csgn()==-1) os << '-';
+    if (!overall_coeff.is_equal(exONE()) &&
+        !overall_coeff.is_equal(exMINUSONE())) {
+        if (ex_to_numeric(overall_coeff).csgn()==-1)
+            (numMINUSONE()*overall_coeff).print(os, precedence);
+        else
+            overall_coeff.print(os, precedence);
+        os << '*';
     }
     }
+    // then proceed with the remaining factors:
     for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
         if (!first) {
             os << '*';
     for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
         if (!first) {
             os << '*';