diff --git a/Lib/test/mathdata/cmath_testcases.txt b/Lib/test/mathdata/cmath_testcases.txt index 7b98b5a2998413d..5600f7713e0877a 100644 --- a/Lib/test/mathdata/cmath_testcases.txt +++ b/Lib/test/mathdata/cmath_testcases.txt @@ -853,6 +853,13 @@ atan0301 atan 1e-155 1.0 -> 0.78539816339744828 178.79691829731851 atan0302 atan 9.9999999999999999e-161 -1.0 -> 0.78539816339744828 -184.55338102980363 atan0303 atan -1e-165 1.0 -> -0.78539816339744828 190.30984376228875 atan0304 atan -9.9998886718268301e-321 -1.0 -> -0.78539816339744828 -368.76019403576692 +-- gh-157859: real part at and next to sqrt(DBL_MIN) = 2**-511 (see atanh0305-0310) +atan0305 atan 1.4916681462400412e-154 1.0 -> 0.78539816339744828 177.445678223346 +atan0306 atan 1.4916681462400413e-154 1.0 -> 0.78539816339744828 177.445678223346 +atan0307 atan 1.4916681462400417e-154 1.0 -> 0.78539816339744828 177.445678223346 +atan0308 atan -1.4916681462400413e-154 1.0 -> -0.78539816339744828 177.445678223346 +atan0309 atan 1.4916681462400413e-154 -1.0 -> 0.78539816339744828 -177.445678223346 +atan0310 atan -1.4916681462400413e-154 -1.0 -> -0.78539816339744828 -177.445678223346 -- Additional real values (mpmath) atan0400 atan 1.7976931348623157e+308 0.0 -> 1.5707963267948966192 0.0 @@ -1043,6 +1050,14 @@ atanh0301 atanh 1.0 9.9999999999999997e-155 -> 177.64562575082149 0.785398163397 atanh0302 atanh -1.0 1e-161 -> -185.70467357630065 0.78539816339744828 atanh0303 atanh 1.0 -1e-165 -> 190.30984376228875 -0.78539816339744828 atanh0304 atanh -1.0 -9.8813129168249309e-324 -> -372.22003596069061 -0.78539816339744828 +-- gh-157859: imaginary part at and next to sqrt(DBL_MIN) = 2**-511, where +-- the near-pole and general formulas meet; the boundary value overflowed. +atanh0305 atanh 1.0 1.4916681462400412e-154 -> 177.445678223346 0.78539816339744828 +atanh0306 atanh 1.0 1.4916681462400413e-154 -> 177.445678223346 0.78539816339744828 +atanh0307 atanh 1.0 1.4916681462400417e-154 -> 177.445678223346 0.78539816339744828 +atanh0308 atanh 1.0 -1.4916681462400413e-154 -> 177.445678223346 -0.78539816339744828 +atanh0309 atanh -1.0 1.4916681462400413e-154 -> -177.445678223346 0.78539816339744828 +atanh0310 atanh -1.0 -1.4916681462400413e-154 -> -177.445678223346 -0.78539816339744828 -- special values atanh1000 atanh 0.0 0.0 -> 0.0 0.0 diff --git a/Misc/NEWS.d/next/Library/2026-09-20-12-53-29.gh-issue-157859.wMR0YM0E.rst b/Misc/NEWS.d/next/Library/2026-09-20-12-53-29.gh-issue-157859.wMR0YM0E.rst new file mode 100644 index 000000000000000..afc957e691ef2e3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-09-20-12-53-29.gh-issue-157859.wMR0YM0E.rst @@ -0,0 +1,2 @@ +Fix :func:`cmath.atanh` and :func:`cmath.atan` returning an infinite +component instead of a finite result for certain inputs near their poles. diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c index e756b550e7753e1..1ed3f39a9cc18b3 100644 --- a/Modules/cmathmodule.c +++ b/Modules/cmathmodule.c @@ -382,7 +382,7 @@ cmath_atanh_impl(PyObject *module, Py_complex z) r.real = z.real/4./h/h; r.imag = copysign(Py_MATH_PI/2., z.imag); errno = 0; - } else if (z.real == 1. && ay < CM_SQRT_DBL_MIN) { + } else if (z.real == 1. && ay <= CM_SQRT_DBL_MIN) { /* C99 standard says: atanh(1+/-0.) should be inf +/- 0i */ if (ay == 0.) { r.real = INF;