Skip to content

gh-156695: Improve accuracy of complex powers with small negative integer exponents - #156757

Open
Aniketsy wants to merge 3 commits into
python:mainfrom
Aniketsy:fix-156695
Open

gh-156695: Improve accuracy of complex powers with small negative integer exponents#156757
Aniketsy wants to merge 3 commits into
python:mainfrom
Aniketsy:fix-156695

Conversation

@Aniketsy

@Aniketsy Aniketsy commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #156695

>>> import math
>>> z = complex(float.fromhex('0x1.47e9c711723f5p+81'),
...            float.fromhex('0x1.38afd1168e49fp+85'))
>>> ref = complex(float.fromhex('0x0.4000000000000p-1022'),
...            float.fromhex('0x0.3ffffffffffffp-1022'))
>>> z ** -12
0j
>>> abs((z**-12 - ref).real) / math.ulp(ref.real)
1125899906842624.0
>>> 0.0j ** 0
(1+0j)
@skirpichev
skirpichev self-requested a review September 1, 2026 09:16
@eendebakpt

Copy link
Copy Markdown
Contributor

The result is improving for the example of the OP, but some results are worse as well. E.g. (3+4j)**-100 or (-2.24e-4+5.09e-5j)**-7 or (8087.7392089611985 + 8087.4504765395295j)**-2. I think we need a more extensive analysis of the overall impact on the results.

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, unfortunately this is not an easy issue.

You could compare old/new results with correctly rounded powers (using e.g. GNU MPC) to see if the net impact is positive. Take look on https://inria.hal.science/hal-04714173 for inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants