From b075df9ab3eb2ebf0b5108caaeedd66526d95e58 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Wed, 10 Nov 1999 19:30:25 +0000 Subject: [PATCH] Hunted down some output bugs. Hope it can be safely piped into Maple now. --- ginac/numeric.cpp | 41 +++++++++++++---------------------------- ginac/print.cpp | 4 ++-- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index c189c3d7..ae047858 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -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 << ")"; } } } diff --git a/ginac/print.cpp b/ginac/print.cpp index 6cfd0a1f..e17292a6 100644 --- a/ginac/print.cpp +++ b/ginac/print.cpp @@ -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; } -- 2.44.0