X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fadd.cpp;h=821649d245b7e443f7de479fd05a2d7d079bd2ee;hp=1f71b0606d7ff9b9ed9f9c943e075412a7e945d4;hb=aaaa74e1033fdd659b4420835b348c72f5fab536;hpb=cfea748404dec5fb2f2e3310d36eeb6640f13824 diff --git a/ginac/add.cpp b/ginac/add.cpp index 1f71b060..821649d2 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's sums of expressions. */ /* - * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -121,16 +121,16 @@ void add::print(const print_context & c, unsigned level) const while (it != itend) { // If the coefficient is -1, it is replaced by a single minus sign - if (it->coeff.compare(_num1) == 0) { + if (it->coeff.is_equal(_ex1)) { it->rest.print(c, precedence()); - } else if (it->coeff.compare(_num_1) == 0) { + } else if (it->coeff.is_equal(_ex_1)) { c.s << "-"; it->rest.print(c, precedence()); - } else if (ex_to(it->coeff).numer().compare(_num1) == 0) { + } else if (ex_to(it->coeff).numer().is_equal(_num1)) { it->rest.print(c, precedence()); c.s << "/"; ex_to(it->coeff).denom().print(c, precedence()); - } else if (ex_to(it->coeff).numer().compare(_num_1) == 0) { + } else if (ex_to(it->coeff).numer().is_equal(_num_1)) { c.s << "-"; it->rest.print(c, precedence()); c.s << "/"; @@ -143,7 +143,7 @@ void add::print(const print_context & c, unsigned level) const // Separator is "+", except if the following expression would have a leading minus sign ++it; - if (it != itend && !(it->coeff.compare(_num0) < 0 || (it->coeff.compare(_num1) == 0 && is_exactly_a(it->rest) && it->rest.compare(_num0) < 0))) + if (it != itend && !(it->coeff.info(info_flags::negative) || (it->coeff.is_equal(_num1) && is_exactly_a(it->rest) && it->rest.info(info_flags::negative)))) c.s << "+"; } @@ -152,10 +152,20 @@ void add::print(const print_context & c, unsigned level) const c.s << '+'; overall_coeff.print(c, precedence()); } - + if (precedence() <= level) c.s << ")"; + } else if (is_a(c)) { + + c.s << class_name() << '('; + op(0).print(c); + for (unsigned i=1; i(e)); - ex numfactor = mulref.overall_coeff; + const ex &numfactor = mulref.overall_coeff; mul *mulcopyp = new mul(mulref); mulcopyp->overall_coeff = _ex1; mulcopyp->clearflag(status_flags::evaluated); @@ -462,7 +472,7 @@ expair add::combine_ex_with_coeff_to_pair(const ex & e, GINAC_ASSERT(is_exactly_a(c)); if (is_ex_exactly_of_type(e, mul)) { const mul &mulref(ex_to(e)); - ex numfactor = mulref.overall_coeff; + const ex &numfactor = mulref.overall_coeff; mul *mulcopyp = new mul(mulref); mulcopyp->overall_coeff = _ex1; mulcopyp->clearflag(status_flags::evaluated); @@ -501,7 +511,7 @@ ex add::recombine_pair_to_ex(const expair & p) const if (ex_to(p.coeff).is_equal(_num1)) return p.rest; else - return p.rest*p.coeff; + return (new mul(p.rest,p.coeff))->setflag(status_flags::dynallocated); } ex add::expand(unsigned options) const