From: Chris Dams Date: Thu, 10 Aug 2006 12:02:55 +0000 (+0000) Subject: Print -x as -x instead of -1.0*x when printing C-source. X-Git-Tag: release_1-3-5~9 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=commitdiff_plain;h=549fc1505ecd2dc16337e30a95da6ecc42a01d70;p=ginac.git Print -x as -x instead of -1.0*x when printing C-source. --- diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 549d1f84..a0eb8a0c 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -283,7 +283,7 @@ ex expairseq::op(size_t i) const ex expairseq::map(map_function &f) const { std::auto_ptr 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(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. */ diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 7ff53bba..5637f593 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -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 "/"