]> www.ginac.de Git - ginac.git/blobdiff - ginac/power.cpp
ncmul::eval(): don't write beyond the end of the vector.
[ginac.git] / ginac / power.cpp
index 4349ab7a59a47959d0d600607e7148dc13084a74..c6bf7b9770d2fa939eb242fef780f6aa84286dc5 100644 (file)
@@ -539,6 +539,7 @@ ex power::eval(int level) const
                                        if (num_coeff.is_positive()) {
                                                mul *mulp = new mul(mulref);
                                                mulp->overall_coeff = _ex1;
+                                               mulp->setflag(status_flags::dynallocated);
                                                mulp->clearflag(status_flags::evaluated);
                                                mulp->clearflag(status_flags::hash_calculated);
                                                return (new mul(power(*mulp,exponent),
@@ -548,6 +549,7 @@ ex power::eval(int level) const
                                                if (!num_coeff.is_equal(*_num_1_p)) {
                                                        mul *mulp = new mul(mulref);
                                                        mulp->overall_coeff = _ex_1;
+                                                       mulp->setflag(status_flags::dynallocated);
                                                        mulp->clearflag(status_flags::evaluated);
                                                        mulp->clearflag(status_flags::hash_calculated);
                                                        return (new mul(power(*mulp,exponent),
@@ -667,12 +669,23 @@ ex power::eval_ncmul(const exvector & v) const
 
 ex power::conjugate() const
 {
-       ex newbasis = basis.conjugate();
-       ex newexponent = exponent.conjugate();
-       if (are_ex_trivially_equal(basis, newbasis) && are_ex_trivially_equal(exponent, newexponent)) {
-               return *this;
+       // conjugate(pow(x,y))==pow(conjugate(x),conjugate(y)) unless on the
+       // branch cut which runs along the negative real axis.
+       if (basis.info(info_flags::positive)) {
+               ex newexponent = exponent.conjugate();
+               if (are_ex_trivially_equal(exponent, newexponent)) {
+                       return *this;
+               }
+               return (new power(basis, newexponent))->setflag(status_flags::dynallocated);
+       }
+       if (exponent.info(info_flags::integer)) {
+               ex newbasis = basis.conjugate();
+               if (are_ex_trivially_equal(basis, newbasis)) {
+                       return *this;
+               }
+               return (new power(newbasis, exponent))->setflag(status_flags::dynallocated);
        }
-       return (new power(newbasis, newexponent))->setflag(status_flags::dynallocated);
+       return conjugate_function(*this).hold();
 }
 
 ex power::real_part() const