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

bpo-44698: Restore complex pow behaviour for small integral exponents #27772

Merged

Conversation

mdickinson
Copy link
Member

@mdickinson mdickinson commented Aug 15, 2021

PR #27278 fixed undefined behaviour in complex exponentiation, but also changed the behaviour for exponentiations whose exponent was a small integer but not actually an int, for example as in (3+4j)**2.0. In particular, the overflow behaviour for these expressions changed:

Prior to #27278:

>>> complex("infj")**2
(nan+nanj)
>>> complex("infj")**2.0
(nan+nanj)

After #27278 :

>>> complex("infj")**2
(nan+nanj)
>>> complex("infj")**2.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: complex exponentiation

This PR restores the old behaviour, but does not re-introduce the undefined behaviour fixed by the original PR.

https://bugs.python.org/issue44698

@@ -174,12 +174,7 @@ c_powi(Py_complex x, long n)
{
Py_complex cn;

if (n > 100 || n < -100) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch is now redundant: the bounds check is performed in the code that calls c_powi.

@mdickinson mdickinson added needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels Aug 15, 2021
@miss-islington
Copy link
Contributor

Thanks @mdickinson for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-27796 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Aug 17, 2021
@bedevere-bot
Copy link

GH-27797 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Aug 17, 2021
@mdickinson
Copy link
Member Author

@gpshead Thank you for the review!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 17, 2021
…pythonGH-27772)

(cherry picked from commit 4b9a2dc)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 17, 2021
…pythonGH-27772)

(cherry picked from commit 4b9a2dc)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
mdickinson added a commit that referenced this pull request Aug 17, 2021
…GH-27772) (GH-27796)

(cherry picked from commit 4b9a2dc)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
mdickinson added a commit that referenced this pull request Aug 17, 2021
…GH-27772) (GH-27797)

(cherry picked from commit 4b9a2dc)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants