all Python 3cmathfunction
cmath.tan()
trigonometry
The tangent of a complex argument. At π/2 it does not fail but returns a huge number, because pi/2 is inexact.
Syntax
cmath.tan(z)
Learners expect a division-by-zero error from tan(π/2), but neither math nor cmath gives one: pi/2 is slightly less than the true π/2, and the result is 1.633123935319537e+16. Check for proximity to the pole yourself. For an imaginary argument tan(ix) = i·tanh(x), so its modulus stays below one.
Examples
import cmath
print(cmath.tan(cmath.pi / 2)) # → (1.633123935319537e+16+0j)
print(cmath.tan(1j)) # → 0.7615941559557649j
See also
Open in the full glossarydocs.python.orgReport an inaccuracy