]> www.ginac.de Git - ginac.git/commitdiff
Hunted down some output bugs. Hope it can be safely piped into Maple now.
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Wed, 10 Nov 1999 19:30:25 +0000 (19:30 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Wed, 10 Nov 1999 19:30:25 +0000 (19:30 +0000)
ginac/numeric.cpp
ginac/print.cpp

index c189c3d7387faccacff265193f2d198dee8dfdcb..ae0478584f1050acd624603df8df094fd3c85235 100644 (file)
@@ -197,13 +197,13 @@ void numeric::printraw(ostream & os) const
 }
 
 // The method print adds to the output so it blends more consistently together
-// with the other routines.
+// with the other routines and produces something compatible to Maple input.
 void numeric::print(ostream & os, unsigned upper_precedence) const
 {
     debugmsg("numeric print", LOGLEVEL_PRINT);
     if (is_real()) {  
         // case 1, real:  x  or  -x
-        if ((realpart(*value) < 0) && (precedence <= upper_precedence)) {
+        if ((precedence<=upper_precedence) && (!is_pos_integer())) {
             os << "(" << *value << ")";
         } else {
             os << *value;
@@ -211,7 +211,7 @@ void numeric::print(ostream & os, unsigned upper_precedence) const
     } else {
         // case 2, imaginary:  y*I  or  -y*I
         if (realpart(*value) == 0) {
-            if ((imagpart(*value) < 0) && (precedence <= upper_precedence)) {
+            if ((precedence<=upper_precedence) && (imagpart(*value) < 0)) {
                 if (imagpart(*value) == -1) {
                     os << "(-I)";
                 } else {
@@ -230,37 +230,22 @@ void numeric::print(ostream & os, unsigned upper_precedence) const
             }
         } else {
             // case 3, complex:  x+y*I  or  x-y*I  or  -x+y*I  or  -x-y*I
-            if ((realpart(*value) < 0) && (precedence <= upper_precedence)) {
-                os << "(" << realpart(*value);
-                if (imagpart(*value) < 0) {
-                    if (imagpart(*value) == -1) {
-                        os << "-I)";
-                    } else {
-                        os << imagpart(*value) << "*I)";
-                    }
+            if (precedence <= upper_precedence) os << "(";
+            os << realpart(*value);
+            if (imagpart(*value) < 0) {
+                if (imagpart(*value) == -1) {
+                    os << "-I";
                 } else {
-                    if (imagpart(*value) == 1) {
-                        os << "+I)";
-                    } else {
-                        os << "+" << imagpart(*value) << "*I)";
-                    }
+                    os << imagpart(*value) << "*I";
                 }
             } else {
-                os << realpart(*value);
-                if (imagpart(*value) < 0) {
-                    if (imagpart(*value) == -1) {
-                        os << "-I";
-                    } else {
-                        os << imagpart(*value) << "*I";
-                    }
+                if (imagpart(*value) == 1) {
+                    os << "+I";
                 } else {
-                    if (imagpart(*value) == 1) {
-                        os << "+I";
-                    } else {
-                        os << "+" << imagpart(*value) << "*I";
-                    }
+                    os << "+" << imagpart(*value) << "*I";
                 }
             }
+            if (precedence <= upper_precedence) os << ")";
         }
     }
 }
index 6cfd0a1f8236a4fa5b9ff7e9b885654ce26ed173..e17292a6d9757350c5202e1e507e4a158391b8b8 100644 (file)
@@ -173,13 +173,13 @@ void add::print(ostream & os, unsigned upper_precedence) const
             os << "-";
         } else {
             if (cit->coeff != 1) {
-                os << cit->coeff;
+                (cit->coeff).print(os,precedence);
                 os << "*";
             }
         }
         os << cit->rest;
     }
-    if (!overall_coeff.is_equal(exZERO())) {
+    if (!overall_coeff.is_zero()) {
         if (overall_coeff > 0) os << '+';
         os << overall_coeff;
     }