Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-44339: Fix math.pow corner case to comply with IEEE 754 #26606

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

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

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
@mdickinson mdickinson deleted the fix-float-pow-ieee-754-corner-case branch June 12, 2021 09:23
jdevries3133 pushed a commit to jdevries3133/cpython that referenced this pull request 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.
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.