[issue43830] (-1) ** 0.5 returns (6.123233995736766e-17+1j) instead of 1j

Mark Dickinson report at bugs.python.org
Tue Apr 13 09:48:06 EDT 2021


Mark Dickinson <dickinsm at gmail.com> added the comment:

FWIW, if you're specifically interested in complex square roots rather than powers in general, I'd recommend using `cmath.sqrt(value)` rather than `value**0.5` - there are fewer intermediate steps involved in computing `cmath.sqrt`, and the returned value will in general be a bit more accurate, and better defined in corner cases. (And probably slightly faster too, in the rare situations where that matters.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43830>
_______________________________________


More information about the Python-bugs-list mailing list