all Python 3cmathfunction
cmath.tanh()
hyperbolic functions
The hyperbolic tangent of a complex argument; for an imaginary argument tanh(i·x) = i·tan(x).
Syntax
cmath.tanh(z)
tanh(iπ/4) should be exactly 1j, but it prints 0.9999999999999999j, a typical cmath picture: an answer that is exact in mathematics differs in the last digit. So compare with cmath.isclose and round before printing. For a real x, math.tanh returns a float and needs no .real.
Examples
import cmath
z = cmath.tanh(1j * cmath.pi / 4)
print(z) # → 0.9999999999999999j
print(cmath.isclose(z, 1j)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy