]> www.ginac.de Git - ginac.git/blobdiff - ginac/power.cpp
[BUGFIX] Fix crash in parser.
[ginac.git] / ginac / power.cpp
index e5d36ee362d7879cf2afb12bc862d2d923acb1d0..c30c9547975139713fceb0aa4db1cf15f840859d 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's symbolic exponentiation (basis^exponent). */
 
 /*
- *  GiNaC Copyright (C) 1999-2019 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2024 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
@@ -140,7 +140,7 @@ void power::do_print_latex(const print_latex & c, unsigned level) const
 static void print_sym_pow(const print_context & c, const symbol &x, int exp)
 {
        // Optimal output of integer powers of symbols to aid compiler CSE.
-       // C.f. ISO/IEC 14882:2011, section 1.9 [intro execution], paragraph 15
+       // C.f. ISO/IEC 14882:2011, section 1.9 [intro.execution], paragraph 15
        // to learn why such a parenthesation is really necessary.
        if (exp == 1) {
                x.print(c);
@@ -619,7 +619,7 @@ ex power::subs(const exmap & m, unsigned options) const
 
        if (!are_ex_trivially_equal(basis, subsed_basis)
         || !are_ex_trivially_equal(exponent, subsed_exponent)) 
-               return power(subsed_basis, subsed_exponent).subs_one_level(m, options);
+               return dynallocate<power>(subsed_basis, subsed_exponent);
 
        if (!(options & subs_options::algebraic))
                return subs_one_level(m, options);
@@ -809,9 +809,10 @@ ex power::expand(unsigned options) const
                ex coeff=(possign? _ex1 : _ex_1);
                if (m.overall_coeff.info(info_flags::positive) && m.overall_coeff != _ex1)
                        prodseq.push_back(pow(m.overall_coeff, exponent));
-               else if (m.overall_coeff.info(info_flags::negative) && m.overall_coeff != _ex_1)
+               else if (m.overall_coeff.info(info_flags::negative) && m.overall_coeff != _ex_1) {
                        prodseq.push_back(pow(-m.overall_coeff, exponent));
-               else
+                       coeff = -coeff;
+               } else
                        coeff *= m.overall_coeff;
 
                // If positive/negative factors are found, then extract them.