Python Glossary Русский

all Python 3cmathfunction

cmath.acos()

trigonometry

The arccosine of a complex number. For real values outside [-1, 1] it gives a purely imaginary or complex result.

Syntax

cmath.acos(z)

A classic mistake is the angle between vectors via acos(dot / (|a|·|b|)): rounding can make the ratio 1.0000000000000002. math.acos then raises ValueError, while cmath.acos returns an imaginary number like -2.1e-08j, and the error travels on unnoticed. acos(2) equals -1.3169578969248166j, with no real part at all.

Examples

import cmath
print(cmath.acos(2))  # → -1.3169578969248166j
print(cmath.acos(0.5).real == cmath.pi / 3)  # → False
print(cmath.isclose(cmath.acos(0.5), cmath.pi / 3))  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy