python / python/cpython

cmath.atanh() returns infinity for complex(1.0, 2.0**-511)

オープン
#157,859 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

@skirpichev がすでに取り組んでいます。

2026年9月20日 から。

extension-modules type-bug
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

cmath.atanh() returns an infinite real part for a finite input whose
result should be finite:

>>> import cmath
>>> import math
>>> y = 2.0**-511
>>> cmath.atanh(complex(1.0, y))
(inf+0.7853981633974483j)

The expected result is approximately
(177.445678223346+0.7853981633974483j). The real part is approximately
256 * math.log(2).

The immediately adjacent floating-point inputs both give finite results:

>>> cmath.atanh(complex(1.0, math.nextafter(y, 0.0)))
(177.445678223346+0.7853981633974483j)
>>> cmath.atanh(complex(1.0, math.nextafter(y, math.inf)))
(177.445678223346+0.7853981633974483j)

The same problem occurs for all four sign combinations of the real and
imaginary parts.

In Modules/cmathmodule.c, cmath_atanh_impl() selects the near-pole
formula using ay < CM_SQRT_DBL_MIN. At equality, the general formula
instead forms 4.0 / DBL_MIN, which overflows before the logarithm is
evaluated. Changing the comparison to <= includes the boundary in the
existing near-pole branch.

This also affects cmath.atan(), which uses the same implementation:

>>> cmath.atan(complex(y, 1.0))
(0.7853981633974483+infj)

Here the expected result is approximately
(0.7853981633974483+177.445678223346j).

Reproduced on CPython 3.14.7, 3.14.4, and main. x86-64 Linux (glibc).

CPython versions tested on:

CPython main branch, 3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-157860

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。