>>> complex('inf')**1j
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
complex('inf')**1j
~~~~~~~~~~~~~~^^~~
ZeroDivisionError: zero to a negative or complex power
The base is not zero. The result should be nan+nanj, as in the GNU MPC.
_Py_c_pow() computes an infinite phase here, and cos() and sin() of an infinite argument are domain errors, so libm sets errno to EDOM. complex_pow() translates any EDOM to ZeroDivisionError, as it cannot distinguish it from the EDOM set for a zero base.
Any finite base for which the phase overflows is affected too:
>>> complex(1e300)**complex(0, 1e308)
ZeroDivisionError: zero to a negative or complex power
>>> complex(2)**complex(0, float('inf'))
ZeroDivisionError: zero to a negative or complex power
sin() and cos() set errno only for infinite arguments, so it is enough to discard errno in _Py_c_pow() after computing the result: _Py_ADJUST_ERANGE2() recovers ERANGE from the result itself.
Noticed by @hpkfft in #156694.
Linked PRs
The base is not zero. The result should be
nan+nanj, as in the GNU MPC._Py_c_pow()computes an infinitephasehere, andcos()andsin()of an infinite argument are domain errors, so libm setserrnotoEDOM.complex_pow()translates anyEDOMtoZeroDivisionError, as it cannot distinguish it from theEDOMset for a zero base.Any finite base for which the phase overflows is affected too:
sin()andcos()seterrnoonly for infinite arguments, so it is enough to discarderrnoin_Py_c_pow()after computing the result:_Py_ADJUST_ERANGE2()recoversERANGEfrom the result itself.Noticed by @hpkfft in #156694.
Linked PRs