python / python/cpython

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

Đang mở
#157,859 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

@skirpichev đang làm issue này rồi.

Từ ngày 20/9/2026.

extension-modules type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.