Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A negative base raised to a rational exponent should not produce a co… #1644

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions symengine/integer.h
Expand Up @@ -82,6 +82,11 @@ class Integer : public Number
{
return false;
}
//! \return `true` if even
inline virtual bool is_even() const
{
return this->i % 2 == 0;
}

/* These are very fast methods for add/sub/mul/div/pow on Integers only */
//! Fast Integer Addition
Expand Down
5 changes: 5 additions & 0 deletions symengine/real_double.h
Expand Up @@ -382,6 +382,11 @@ class RealDouble : public Number
RCP<const Number> powreal(const Rational &other) const
{
if (i < 0) {
if (!other.get_den().get()->is_even()) {
double k = other.get_num().get()->is_even() ? 1.0 : -1.0;
return make_rcp<const RealDouble>(
k * std::pow(-i, mp_get_d(other.as_rational_class())));
}
return number(std::pow(std::complex<double>(i),
mp_get_d(other.as_rational_class())));
}
Expand Down