This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson, sable
Date 2010-09-23.10:36:20
SpamBayes Score 3.6804615e-11
Marked as misclassified No
Message-id <1285238183.07.0.773949712605.issue9920@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2010-09-23 10:36:23mark.dickinsonsetrecipients: + mark.dickinson, sable
2010-09-23 10:36:23mark.dickinsonsetmessageid: <1285238183.07.0.773949712605.issue9920@psf.upfronthosting.co.za>
2010-09-23 10:36:21mark.dickinsonlinkissue9920 messages
2010-09-23 10:36:20mark.dickinsoncreate