Python Glossary Русский

all Python 3cmathfunction

cmath.asin()

trigonometry

The arcsine of a complex number. Unlike math.asin, it accepts values outside [-1, 1] and returns a complex angle.

Syntax

cmath.asin(z)

math.asin(2) raises ValueError, while cmath.asin(2) returns (1.5707963267948966+1.3169578969248166j). That suits mathematics but is risky in geometry: if rounding pushes a value to 1.0000000000000002, cmath silently gives a complex angle instead of an error. There, prefer math.asin and clamp the argument with min(1, max(-1, x)).

Examples

import cmath
import math
print(cmath.asin(2))  # → (1.5707963267948966+1.3169578969248166j)
try:
    math.asin(2)
except ValueError as e:
    print(type(e).__name__)  # → ValueError

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy