]> www.ginac.de Git - ginac.git/commitdiff
Print -x as -x instead of -1.0*x when printing C-source.
authorChris Dams <Chris.Dams@mi.infn.it>
Thu, 10 Aug 2006 12:02:55 +0000 (12:02 +0000)
committerChris Dams <Chris.Dams@mi.infn.it>
Thu, 10 Aug 2006 12:02:55 +0000 (12:02 +0000)
ginac/expairseq.cpp
ginac/mul.cpp

index 549d1f845779e173f7466387cb038aa90937d9b6..a0eb8a0c655f371e53434dbc9fca0918463dedaf 100644 (file)
@@ -283,7 +283,7 @@ ex expairseq::op(size_t i) const
 ex expairseq::map(map_function &f) const
 {
        std::auto_ptr<epvector> v(new epvector);
-       v->reserve(seq.size());
+       v->reserve(seq.size()+1);
 
        epvector::const_iterator cit = seq.begin(), last = seq.end();
        while (cit != last) {
@@ -293,8 +293,15 @@ ex expairseq::map(map_function &f) const
 
        if (overall_coeff.is_equal(default_overall_coeff()))
                return thisexpairseq(v, default_overall_coeff());
-       else
-               return thisexpairseq(v, f(overall_coeff));
+       else {
+      ex newcoeff = f(overall_coeff);
+      if(is_a<numeric>(newcoeff))
+         return thisexpairseq(v, newcoeff);
+      else {
+         v->push_back(split_ex_to_pair(newcoeff));
+         return thisexpairseq(v, default_overall_coeff());
+      }
+   }
 }
 
 /** Perform coefficient-wise automatic term rewriting rules in this class. */
index 7ff53bba835c338d2001f2f14755c02b973b856e..5637f593d12b8710b2d1c457af27b0f4eccc093c 100644 (file)
@@ -218,8 +218,12 @@ void mul::do_print_csrc(const print_csrc & c, unsigned level) const
                c.s << "(";
 
        if (!overall_coeff.is_equal(_ex1)) {
-               overall_coeff.print(c, precedence());
-               c.s << "*";
+               if (overall_coeff.is_equal(_ex_1))
+                       c.s << "-";
+               else {
+                       overall_coeff.print(c, precedence());
+                       c.s << "*";
+               }
        }
 
        // Print arguments, separated by "*" or "/"