X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fnumeric.cpp;h=0303b6d7ccee81b647e6d4777819b8a061c8f662;hp=880e0a7ebbde60bcbf0ec559527cc69769f7dd02;hb=5041748e650b3a2da73ae6128c83f88698d38dcf;hpb=aa6281216091efd92dc5fcc3f96c7189114e80f1 diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index 880e0a7e..0303b6d7 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -346,18 +346,27 @@ DEFAULT_UNARCHIVE(numeric) * want to visibly distinguish from cl_LF. * * @see numeric::print() */ -static void print_real_number(std::ostream &os, const cln::cl_R &num) +static void print_real_number(const print_context & c, const cln::cl_R &x) { cln::cl_print_flags ourflags; - if (cln::instanceof(num, cln::cl_RA_ring)) { - // case 1: integer or rational, nothing special to do: - cln::print_real(os, ourflags, num); + if (cln::instanceof(x, cln::cl_RA_ring)) { + // case 1: integer or rational + if (cln::instanceof(x, cln::cl_I_ring) || + !is_a(c)) { + cln::print_real(c.s, ourflags, x); + } else { // rational output in LaTeX context + c.s << "\\frac{"; + cln::print_real(c.s, ourflags, cln::numerator(cln::the(x))); + c.s << "}{"; + cln::print_real(c.s, ourflags, cln::denominator(cln::the(x))); + c.s << '}'; + } } else { // case 2: float // make CLN believe this number has default_float_format, so it prints // 'E' as exponent marker instead of 'L': - ourflags.default_float_format = cln::float_format(cln::the(num)); - cln::print_real(os, ourflags, num); + ourflags.default_float_format = cln::float_format(cln::the(x)); + cln::print_real(c.s, ourflags, x); } } @@ -419,10 +428,10 @@ void numeric::print(const print_context & c, unsigned level) const // case 1, real: x or -x if ((precedence() <= level) && (!this->is_nonneg_integer())) { c.s << par_open; - print_real_number(c.s, r); + print_real_number(c, r); c.s << par_close; } else { - print_real_number(c.s, r); + print_real_number(c, r); } } else { if (cln::zerop(r)) { @@ -432,7 +441,7 @@ void numeric::print(const print_context & c, unsigned level) const c.s << par_open+imag_sym+par_close; } else { c.s << par_open; - print_real_number(c.s, i); + print_real_number(c, i); c.s << mul_sym+imag_sym+par_close; } } else { @@ -442,7 +451,7 @@ void numeric::print(const print_context & c, unsigned level) const if (i == -1) { c.s << "-" << imag_sym; } else { - print_real_number(c.s, i); + print_real_number(c, i); c.s << mul_sym+imag_sym; } } @@ -451,12 +460,12 @@ void numeric::print(const print_context & c, unsigned level) const // case 3, complex: x+y*I or x-y*I or -x+y*I or -x-y*I if (precedence() <= level) c.s << par_open; - print_real_number(c.s, r); + print_real_number(c, r); if (i < 0) { if (i == -1) { c.s << "-"+imag_sym; } else { - print_real_number(c.s, i); + print_real_number(c, i); c.s << mul_sym+imag_sym; } } else { @@ -464,7 +473,7 @@ void numeric::print(const print_context & c, unsigned level) const c.s << "+"+imag_sym; } else { c.s << "+"; - print_real_number(c.s, i); + print_real_number(c, i); c.s << mul_sym+imag_sym; } } @@ -1423,10 +1432,7 @@ const numeric zeta(const numeric &x) if (cln::zerop(x.to_cl_N()-aux)) return cln::zeta(aux); } - std::clog << "zeta(" << x - << "): Does anybody know a good way to calculate this numerically?" - << std::endl; - return numeric(0); + throw dunno(); } @@ -1434,17 +1440,11 @@ const numeric zeta(const numeric &x) * This is only a stub! */ const numeric lgamma(const numeric &x) { - std::clog << "lgamma(" << x - << "): Does anybody know a good way to calculate this numerically?" - << std::endl; - return numeric(0); + throw dunno(); } const numeric tgamma(const numeric &x) { - std::clog << "tgamma(" << x - << "): Does anybody know a good way to calculate this numerically?" - << std::endl; - return numeric(0); + throw dunno(); } @@ -1452,10 +1452,7 @@ const numeric tgamma(const numeric &x) * This is only a stub! */ const numeric psi(const numeric &x) { - std::clog << "psi(" << x - << "): Does anybody know a good way to calculate this numerically?" - << std::endl; - return numeric(0); + throw dunno(); } @@ -1463,10 +1460,7 @@ const numeric psi(const numeric &x) * This is only a stub! */ const numeric psi(const numeric &n, const numeric &x) { - std::clog << "psi(" << n << "," << x - << "): Does anybody know a good way to calculate this numerically?" - << std::endl; - return numeric(0); + throw dunno(); }