]> www.ginac.de Git - ginac.git/blobdiff - ginac/print.cpp
#ifndef around namespace GiNaC { }
[ginac.git] / ginac / print.cpp
index f797dc6b1e9ebd59f1c4e525fa27264c64366709..c1e9841c9e4858fa409c2bbcb0336db3bc6a51d0 100644 (file)
 #include "symbol.h"
 #include "debugmsg.h"
 
+#ifndef NO_GINAC_NAMESPACE
 namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 void ex::print(ostream & os, unsigned upper_precedence) const
 {
     debugmsg("ex print",LOGLEVEL_PRINT);
-    ASSERT(bp!=0);
+    GINAC_ASSERT(bp!=0);
     bp->print(os,upper_precedence);
 }
 
 void ex::dbgprint(void) const
 {
     debugmsg("ex dbgprint",LOGLEVEL_PRINT);
-    ASSERT(bp!=0);
+    GINAC_ASSERT(bp!=0);
     bp->dbgprint();
 }
 
@@ -146,7 +148,8 @@ void add::print(ostream & os, unsigned upper_precedence) const
             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
@@ -168,10 +171,17 @@ void mul::print(ostream & os, unsigned upper_precedence) const
     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 << '*';
@@ -251,4 +261,6 @@ void matrix::print(ostream & os, unsigned upper_precedence) const
     os << m[row*col-1] << "]] ]]";
 }
 
+#ifndef NO_GINAC_NAMESPACE
 } // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE