From 0b6728152f214752dc97f02d2dad39003b10cac5 Mon Sep 17 00:00:00 2001
From: "Vladimir V. Kisil" <kisilv@maths.leeds.ac.uk>
Date: Wed, 9 Aug 2017 10:01:06 +0100
Subject: [PATCH] Fix bug in evaluation of real and imaginary parts of powers.

Signed-off-by: Vladimir V. Kisil <kisilv@maths.leeds.ac.uk>
---
 ginac/power.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/ginac/power.cpp b/ginac/power.cpp
index 26194928..037848d3 100644
--- a/ginac/power.cpp
+++ b/ginac/power.cpp
@@ -669,7 +669,8 @@ ex power::real_part() const
 	// basis == a+I*b, exponent == c+I*d
 	const ex a = basis.real_part();
 	const ex c = exponent.real_part();
-	if (basis.is_equal(a) && exponent.is_equal(c)) {
+	if (basis.is_equal(a) && exponent.is_equal(c)
+		&& (a.info(info_flags::nonnegative) || c.info(info_flags::integer))) {
 		// Re(a^c)
 		return *this;
 	}
@@ -704,7 +705,8 @@ ex power::imag_part() const
 	// basis == a+I*b, exponent == c+I*d
 	const ex a = basis.real_part();
 	const ex c = exponent.real_part();
-	if (basis.is_equal(a) && exponent.is_equal(c)) {
+	if (basis.is_equal(a) && exponent.is_equal(c)
+		&& (a.info(info_flags::nonnegative) || c.info(info_flags::integer))) {
 		// Im(a^c)
 		return 0;
 	}
-- 
2.13.2

