X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;ds=sidebyside;f=ginac%2Fpower.cpp;h=0730e3c8bf7fc385c5d4d1c1a97b6c565997cfab;hb=afb2ad021243dc915f8400b9053c78a03d1538d7;hp=85e5bd6c9a92e76c470dc83c527a4d6eaa85a0d0;hpb=e14a5df66cc2b30e31e58418079704f4dcd52616;p=ginac.git diff --git a/ginac/power.cpp b/ginac/power.cpp index 85e5bd6c..0730e3c8 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's symbolic exponentiation (basis^exponent). */ /* - * GiNaC Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2003 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 @@ -125,7 +125,7 @@ void power::print(const print_context & c, unsigned level) const // Integer powers of symbols are printed in a special, optimized way if (exponent.info(info_flags::integer) - && (is_exactly_a(basis) || is_exactly_a(basis))) { + && (is_a(basis) || is_a(basis))) { int exp = ex_to(exponent).to_int(); if (exp > 0) c.s << '('; @@ -172,11 +172,23 @@ void power::print(const print_context & c, unsigned level) const bool is_tex = is_a(c); - if (exponent.is_equal(_ex1_2)) { + if (is_tex && is_exactly_a(exponent) && ex_to(exponent).is_negative()) { + + // Powers with negative numeric exponents are printed as fractions in TeX + c.s << "\\frac{1}{"; + power(basis, -exponent).eval().print(c); + c.s << "}"; + + } else if (exponent.is_equal(_ex1_2)) { + + // Square roots are printed in a special way c.s << (is_tex ? "\\sqrt{" : "sqrt("); basis.print(c); c.s << (is_tex ? '}' : ')'); + } else { + + // Ordinary output of powers using '^' or '**' if (precedence() <= level) c.s << (is_tex ? "{(" : "("); basis.print(c, precedence());