]> www.ginac.de Git - ginac.git/commitdiff
* Fix broken C output. (Chris Dams)
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Mon, 2 Sep 2002 20:42:56 +0000 (20:42 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Mon, 2 Sep 2002 20:42:56 +0000 (20:42 +0000)
ginac/mul.cpp

index 28233b302ebc1b1485b390c055df10586136c6c7..211855a6613d2cc9dfabe370ae6272e7b4460143 100644 (file)
@@ -141,25 +141,32 @@ void mul::print(const print_context & c, unsigned level) const
                while (it != itend) {
 
                        // If the first argument is a negative integer power, it gets printed as "1.0/<expr>"
-                       if (it == seq.begin() && ex_to<numeric>(it->coeff).is_integer() && it->coeff.info(info_flags::negative)) {
-                               if (is_a<print_csrc_cl_N>(c))
+                       bool needclosingparenthesis = false;
+                       if (it == seq.begin() && it->coeff.info(info_flags::negint)) {
+                               if (is_a<print_csrc_cl_N>(c)) {
                                        c.s << "recip(";
-                               else
+                                       needclosingparenthesis = true;
+                               } else
                                        c.s << "1.0/";
                        }
 
                        // If the exponent is 1 or -1, it is left out
                        if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1))
                                it->rest.print(c, precedence());
-                       else {
+                       else if (it->coeff.info(info_flags::negint))
                                // Outer parens around ex needed for broken gcc-2.95 parser:
-                               (ex(power(it->rest, abs(ex_to<numeric>(it->coeff))))).print(c, level);
-                       }
+                               (ex(power(it->rest, -ex_to<numeric>(it->coeff)))).print(c, level);
+                       else
+                               // Outer parens around ex needed for broken gcc-2.95 parser:
+                               (ex(power(it->rest, ex_to<numeric>(it->coeff)))).print(c, level);
+
+                       if (needclosingparenthesis)
+                               c.s << ")";
 
                        // Separator is "/" for negative integer powers, "*" otherwise
                        ++it;
                        if (it != itend) {
-                               if (ex_to<numeric>(it->coeff).is_integer() && it->coeff.info(info_flags::negative))
+                               if (it->coeff.info(info_flags::negint))
                                        c.s << "/";
                                else
                                        c.s << "*";