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.

Title: cmath.atanh has wrong output
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, ezio.melotti, mark.dickinson, rhettinger, stutzbach, 夏熙临
Priority: normal Keywords:

Created on 2015-02-26 00:23 by 夏熙临, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg236636 - (view) Author: 夏熙临 (夏熙临) Date: 2015-02-26 00:23
When I was using cmath.atanh, I found that this function generates wrong output.

For example:

>>> import cmath
>>> cmath.atanh(-1.89)

However, the correct output should be:

Clearly, the sign of the imaginary part is wrong.
msg236646 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2015-02-26 05:17
Both are correct, since atanh requires a branch cut.
msg236836 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2015-02-27 20:48
> Both are correct
Well, strictly speaking only the output with positive imaginary part is correct here: the recommendations of C99 Annex G (which Python's cmath module follows) use the sign of the zero imaginary part to determine which 'side' of the branch cut the input lies on.  In this case, -1.89 is interpreted as complex(-1.89, 0.0), so the imaginary part is a positive zero, and the sign of the imaginary part of the result matches that for complex(-1.89, small_and_positive).

So all four of the following are correct:

>>> cmath.atanh(complex(-1.89, 0.0))
>>> cmath.atanh(complex(-1.89, -0.0))
>>> cmath.atanh(complex(1.89, 0.0))
>>> cmath.atanh(complex(1.89, -0.0))
Date User Action Args
2022-04-11 14:58:13adminsetgithub: 67711
2015-02-27 20:48:13mark.dickinsonsetmessages: + msg236836
2015-02-26 05:17:04benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg236646

resolution: not a bug
2015-02-26 00:31:05ezio.melottisetnosy: + rhettinger, mark.dickinson, stutzbach, ezio.melotti
2015-02-26 00:23:35夏熙临create