You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Leave sign of 0 unspecified for tanh inf + yj #1006
If a is +infinity and b is a positive (i.e., greater than 0) finite number, the result is 1 + 0j
from open-std pages describing ctanh
— ctanh(+∞ + iy) returns 1 + i0sin(2y), for positive-signed finite y.
This matches up to the math (we can derive this from tanh(x + iy) taking the limit as x approaches infinity and constraining y to be finite), and gives us 1 ± 0i, with the sign being inherited from sin(2y) if we care about signed zeros, rather than positive zero in all cases.
This was brought up because this special case is tested by the array API tests, which causes dpnp to fail the test.
import numpy as np
print([np.tanh(complex(np.inf, n)) for n in range(4)])
# [np.complex128(1+0j), np.complex128(1+0j), np.complex128(1-0j), np.complex128(1-0j)]
at least for conda-forge NumPy, there can be discrepancies on PyPI with complex edge cases I've found.
Activity
kgryte commentedon May 15, 2026
Thanks for raising this issue, @ndgrigorian. For complex number special handling, we deferred to behavior described in C99: https://en.cppreference.com/c/numeric/complex/ctanh. Namely,
ndgrigorian commentedon May 15, 2026
yes, but I would argue, that the cppreference page is a bit misleading as well. The ISO standard (final draft) text for C99 also uses
sin(2y).NumPy also gives the same:
at least for conda-forge NumPy, there can be discrepancies on PyPI with complex edge cases I've found.