With #69639 complex arithmetic in Python was extended to support C-like mixed-more rules, where one operand is a float or an int. However, this doesn't affect exponentiation.
Currently we have, for example:
>>> import cmath
>>> z =complex('inf')
>>> z**0.5
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
z**0.5
~^^~~~
OverflowError: complex exponentiation
>>> cmath.sqrt(z)
(inf+0j)
>>> z**2
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
z**2
~^^~
OverflowError: complex exponentiation
which is just meaningless. Note also, that plain multiplication is not too much better in the last case:
>>> z*z
(inf+nanj)
What we actually want here is exp(log(z)*real_exponent):
If Python could compute the principal value correctly in order to produce the correct value for $z^a$, then I'm in favor. Even if the C standard doesn't specify what to do, I think we should follow what Mathematica did (I'll need to check what Sage does as well)
Activity
picnixz commented on Aug 18, 2025
If Python could compute the principal value correctly in order to produce the correct value for $z^a$, then I'm in favor. Even if the C standard doesn't specify what to do, I think we should follow what Mathematica did (I'll need to check what Sage does as well)
skirpichev commented on Aug 19, 2025
Until recent drafts, it has no special case for complex division with lhs real op.
Yes, from https://reference.wolfram.com/language/ref/Power.html:
Though, I don't think that Mathematica has concept of signed zero.
skirpichev commented on Aug 19, 2026
N.B., ISO/IEC 10967 (part 3) has special rules for RxR->C power function (§5.3.1.3).