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-44339: Fix math.pow corner case to comply with IEEE 754 #26606

Merged
merged 9 commits into from Jun 12, 2021

Conversation

@mdickinson
Copy link
Member

@mdickinson mdickinson commented Jun 8, 2021

This PR changes the behaviour of math.pow(0.0, -math.inf) and math.pow(-0.0, -math.inf) to return positive infinity instead of raising ValueError. This makes math.pow consistent with the built-in pow (and the ** operator) for this particular special case, and brings the math.pow special-case handling into compliance with IEEE 754.

Before:

Python 3.11.0a0 (heads/main:257e400a19, Jun  8 2021, 18:00:50) [Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.pow(0.0, -math.inf)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
>>> math.pow(-0.0, -math.inf)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error

After:

Python 3.11.0a0 (heads/fix-float-pow-ieee-754-corner-case:1be10ea32f, Jun  8 2021, 17:43:05) [Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.pow(0.0, -math.inf)
inf
>>> math.pow(-0.0, -math.inf)
inf

https://bugs.python.org/issue44339

Lib/test/ieee754.txt Outdated Show resolved Hide resolved
Lib/test/test_math.py Show resolved Hide resolved
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jun 9, 2021

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@mdickinson mdickinson merged commit 4a42ceb into python:main Jun 12, 2021
13 checks passed
@mdickinson mdickinson deleted the fix-float-pow-ieee-754-corner-case branch Jun 12, 2021
jdevries3133 added a commit to jdevries3133/cpython that referenced this issue Jun 19, 2021
…-26606)

Change the behaviour of `math.pow(0.0, -math.inf)` and `math.pow(-0.0, -math.inf)` to return positive infinity instead of raising `ValueError`. This makes `math.pow` consistent with the built-in `pow` (and the `**` operator) for this particular special case, and brings the `math.pow` special-case handling into compliance with IEEE 754.
JuniorJPDJ added a commit to JuniorJPDJ/cpython that referenced this issue Aug 12, 2021
…-26606)

Change the behaviour of `math.pow(0.0, -math.inf)` and `math.pow(-0.0, -math.inf)` to return positive infinity instead of raising `ValueError`. This makes `math.pow` consistent with the built-in `pow` (and the `**` operator) for this particular special case, and brings the `math.pow` special-case handling into compliance with IEEE 754.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants