Mark Dickinson <dicki...@gmail.com> added the comment:

Thanks;  so it's probably not an optimization bug, but rather a math library 
bug somewhere.

And thanks for the tanh result;  unfortunately I asked the wrong question---I 
meant to ask about atanh(complex(-0.0, 0.0)) :(

Analysis: atan(z) is computed internally as atanh(iz) / i.  So if the imaginary 
part of atan is coming out wrong, it's probably because the real part of atanh 
is incorrect.  So I'd expect atanh(complex(-0.0, 0.0)) to produce 0.0j (instead 
of the correct answer of -0.0 + 0.0j).

The real part of atanh(x + iy) is computed (for a region of the complex plane 
containing 0.0) using the formula:

    real_part = log1p(4.*z.real/((1-z.real)*(1-z.real) + z.imag * z.imag))/4.;

My best guess is that the log1p function is dropping the sign on a negative 
zero.  But in that case I'd expect test_math to fail on your system, too.

Could you try the following experiments, and let me know what you get?  (Feel 
free to stop as soon as your results start to differ from what's below.)

>>> import math, cmath
>>> math.log1p(-0.0)
-0.0
>>> z = complex(-0.0, 0.0)
>>> 4. * z.real
-0.0
>>> (1 - z.real) * (1 - z.real) + z.imag * z.imag
1.0
>>> 4. * z.real / ((1 - z.real) * (1 - z.real) + z.imag * z.imag)
-0.0
>>> math.log1p(4. * z.real / ((1 - z.real) * (1 - z.real) + z.imag * z.imag))
-0.0
>>> math.log1p(4. * z.real / ((1 - z.real) * (1 - z.real) + z.imag * z.imag)) / 
>>> 4.
-0.0
>>> cmath.atanh(z).real
-0.0

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9920>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to