[issue11658] complex sqrt error
STINNER Victor
report at bugs.python.org
Thu Mar 24 03:51:21 CET 2011
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
(-1)**.5 is the same than complex(-1,0)**.5, but it is computed differently than cmath.sqrt(-1).
-1.**0.5 computes:
vabs = math.hypot(-1, 0)
len = pow(vabs, 0.5)
at = math.atan2(0, -1)
phase = at * 0.5
return complex(len*math.cos(phase), len*math.sin(phase))
whereas cmath.sqrt(-1) computes:
ax = math.fabs(-1)
ay = math.fabs(0)
ax /= 8.
s = 2. * math.sqrt(ax + math.hypot(ax, ay/8.))
d = ay / (2.*s)
return complex(d, math.copysign(s, 0))
Anyway, math.sqrt() and cmath.sqrt() are designed to be more precise than x**0.5.
----------
nosy: +haypo, mark.dickinson
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11658>
_______________________________________
More information about the Python-bugs-list
mailing list