-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Invalid corner cases (resulting in nan+nanj) in _Py_c_prod() #120010
Labels
type-bug
An unexpected behavior, bug, or error
Comments
skirpichev
added a commit
to skirpichev/cpython
that referenced
this issue
Jun 4, 2024
In some cases, previosly computed as (nan+nanj), we could recover meaningful component values in the result, see e.g. the C11, Annex G.5.2, routine _Cmuld(): >>> z = 1e300+1j >>> z*(inf+infj) # was (nan+nanj) (nan+infj) That also fix some complex powers for small integer exponents, computed by optimised algorithm (by squaring): >>> z**5 # was (nan+nanj) Traceback (most recent call last): File "<python-input-1>", line 1, in <module> z**5 ~^^~ OverflowError: complex exponentiation
cc @mdickinson |
skirpichev
added a commit
to skirpichev/cpython
that referenced
this issue
Jun 9, 2024
In some cases, previously computed as (nan+nanj), we could recover meaningful component values in the result, see e.g. the C11, Annex G.5.2, routine _Cmultd(): >>> z = 1e300+1j >>> z*(nan+infj) # was (nan+nanj) (-inf+infj) That also fix some complex powers for small integer exponents, computed with optimised algorithm (by squaring): >>> z**5 # was (nan+nanj) Traceback (most recent call last): File "<python-input-1>", line 1, in <module> z**5 ~^^~ OverflowError: complex exponentiation
skirpichev
added a commit
to skirpichev/cpython
that referenced
this issue
Jun 9, 2024
In some cases, previously computed as (nan+nanj), we could recover meaningful component values in the result, see e.g. the C11, Annex G.5.2, routine _Cmultd(): >>> z = 1e300+1j >>> z*(nan+infj) # was (nan+nanj) (-inf+infj) That also fix some complex powers for small integer exponents, computed with optimised algorithm (by squaring): >>> z**5 # was (nan+nanj) Traceback (most recent call last): File "<python-input-1>", line 1, in <module> z**5 ~^^~ OverflowError: complex exponentiation
PR is ready for review: #120287 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Bug description:
Reproducer:
c.f. C code
That quickly leads to problems in optimized algorithm for exponentiation (by squaring), that claims to be "more accurate":
Following patch (mostly a literal translation of the
_Cmultd()
routine from the C11 Annex G.5.2) should solve the issue.a patch
c.f. clang's version:
https://github.com/llvm/llvm-project/blob/4973ad47181710d2a69292018cad7bc6f95a6c1a/libcxx/include/complex#L712-L792
Also, maybe
_Py_c_prod()
code should set errno on overflows, just as_Py_c_abs()
. E.g. with above version we have:If this issue does make sense, I'll provide a patch.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: