X-Git-Url: https://ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fnumeric.cpp;h=ef4e3e929ce5732f854bfae80d3f72f9f55e2b34;hb=7ece13ddcc174e28b7b333e5d09900bc90f3dd78;hp=1308c9e1cf736ddda40e9eb9247aee6bf1a7a95f;hpb=06eb6b761f4b9d9eed4decd8ed50d94b40b94a0e;p=ginac.git diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index 1308c9e1..ef4e3e92 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -410,15 +410,18 @@ void numeric::print(const print_context & c, unsigned level) const c.s.flags(oldflags); } else { - - cln::cl_R r = cln::realpart(cln::the(value)); - cln::cl_R i = cln::imagpart(cln::the(value)); + const std::string par_open = is_of_type(c, print_latex) ? "{(" : "("; + const std::string par_close = is_of_type(c, print_latex) ? ")}" : ")"; + const std::string imag_sym = is_of_type(c, print_latex) ? "i" : "I"; + const std::string mul_sym = is_of_type(c, print_latex) ? " " : "*"; + const cln::cl_R r = cln::realpart(cln::the(value)); + const cln::cl_R i = cln::imagpart(cln::the(value)); if (cln::zerop(i)) { // case 1, real: x or -x if ((precedence <= level) && (!this->is_nonneg_integer())) { - c.s << "("; + c.s << par_open; print_real_number(c.s, r); - c.s << ")"; + c.s << par_close; } else { print_real_number(c.s, r); } @@ -427,47 +430,47 @@ void numeric::print(const print_context & c, unsigned level) const // case 2, imaginary: y*I or -y*I if ((precedence <= level) && (i < 0)) { if (i == -1) { - c.s << "(-I)"; + c.s << par_open+imag_sym+par_close; } else { - c.s << "("; + c.s << par_open; print_real_number(c.s, i); - c.s << "*I)"; + c.s << mul_sym+imag_sym+par_close; } } else { if (i == 1) { - c.s << "I"; + c.s << imag_sym; } else { if (i == -1) { - c.s << "-I"; + c.s << "-" << imag_sym; } else { print_real_number(c.s, i); - c.s << "*I"; + c.s << mul_sym+imag_sym; } } } } else { // case 3, complex: x+y*I or x-y*I or -x+y*I or -x-y*I if (precedence <= level) - c.s << "("; + c.s << par_open; print_real_number(c.s, r); if (i < 0) { if (i == -1) { - c.s << "-I"; + c.s << "-"+imag_sym; } else { print_real_number(c.s, i); - c.s << "*I"; + c.s << mul_sym+imag_sym; } } else { if (i == 1) { - c.s << "+I"; + c.s << "+"+imag_sym; } else { c.s << "+"; print_real_number(c.s, i); - c.s << "*I"; + c.s << mul_sym+imag_sym; } } if (precedence <= level) - c.s << ")"; + c.s << par_close; } } } @@ -935,13 +938,13 @@ bool numeric::is_real(void) const bool numeric::operator==(const numeric &other) const { - return equal(cln::the(value), cln::the(other.value)); + return cln::equal(cln::the(value), cln::the(other.value)); } bool numeric::operator!=(const numeric &other) const { - return !equal(cln::the(value), cln::the(other.value)); + return !cln::equal(cln::the(value), cln::the(other.value)); } @@ -1111,7 +1114,7 @@ const numeric numeric::denom(void) const if (this->is_integer()) return _num1(); - if (instanceof(value, cln::cl_RA_ring)) + if (cln::instanceof(value, cln::cl_RA_ring)) return numeric(cln::denominator(cln::the(value))); if (!this->is_real()) { // complex case, handle Q(i): @@ -1747,8 +1750,8 @@ const numeric irem(const numeric &a, const numeric &b, numeric &q) const numeric iquo(const numeric &a, const numeric &b) { if (a.is_integer() && b.is_integer()) - return truncate1(cln::the(a.to_cl_N()), - cln::the(b.to_cl_N())); + return cln::truncate1(cln::the(a.to_cl_N()), + cln::the(b.to_cl_N())); else return _num0(); }