Python math.asin() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math module

Definition

math.asin(x) returns the arc sine (inverse sine) of x in radians, within the principal range [-pi / 2, pi / 2].

Inputs must lie in [-1, 1]; any value outside that interval raises ValueError. Wrap the result with math.degrees() if you need degrees.

math.asin() is a function in Python's standard math module: import it with import math and call math.asin(...), or import the name directly with from math import asin.

Syntax

Import math and pass a ratio in [-1, 1].

python
import math

angle_rad = math.asin(ratio)
CallWhat it does
math.asin(0)Returns 0.0.
math.asin(0.5)Returns approximately 0.523598... (pi / 6).
math.asin(-1.0)Returns approximately -1.570796... (-pi / 2).
math.asin(1.1)Raises ValueError: outside [-1, 1].

When computing ratios like y / hypot(x, y), tiny rounding drift can push 1.0 to 1.0000000000000002; clamp with max(-1.0, min(1.0, r)) before calling asin().

Function signatures
python
math.asin(x, /)
# returns: float arc sine in [-pi/2, pi/2] for -1 <= x <= 1

Parameters

ParameterDescription
xRequired positional number (int or float) between -1 and 1 inclusive.

Return Value

Return ValueDescription
floatAngle in radians inside [-pi / 2, pi / 2]; returns nan for nan.

Python Examples

Example 1 — Find Wheelchair Ramp Angles From Rise and Length

Convert vertical rise divided by ramp length into degrees with math.degrees(math.asin(...)).

python
import math

for rise, length in [(0.0, 5.0), (1.0, 12.0), (1.0, 2.0), (4.0, 4.0)]:
    angle_deg = math.degrees(math.asin(rise / length))
    print(f"rise={rise} len={length} -> {angle_deg:.2f} deg")

How It Works

  1. Rise over hypotenuse. Dividing vertical height by ramp slope gives the sine ratio in [0, 1].
  2. ADA-style 1:12 slope. A one-unit rise over a twelve-unit ramp sits at 4.78 degrees.
  3. Half and full ratios. Ratios 0.5 and 1.0 yield exact angles 30.00 and 90.00 degrees.

Example 2 — Calculate Light Refraction Angles With Snell Law

Solve sin(theta2) = (n1 / n2) * sin(theta1) for air entering glass.

python
import math

n_air, n_glass = 1.0, 1.5
for incident_deg in [0, 30, 45, 60]:
    sin_out = (n_air / n_glass) * math.sin(math.radians(incident_deg))
    out_deg = math.degrees(math.asin(sin_out))
    print(f"in={incident_deg:>2} deg -> out={out_deg:.2f} deg")

How It Works

  1. Refractive ratio. Light bends closer to normal when moving from air (1.0) into glass (1.5).
  2. Normal incidence. Zero-degree entry passes straight through at 0.00 degrees.
  3. Angle conversion chain. radians() prepares the input sine and degrees() turns the arc sine output back to degrees.

Example 3 — Clamp Float Drift and Handle Domain Errors

Prevent spurious ValueError on 1.0 + 1e-15 by clamping to [-1.0, 1.0].

python
import math

drifted = 1.0 + 1e-15
try:
    math.asin(drifted)
except ValueError:
    print("unclamped drift > 1.0 raises ValueError")

clamped = max(-1.0, min(1.0, drifted))
print(math.degrees(math.asin(clamped)))

How It Works

  1. Subtle drift fails. Even 1e-15 above 1.0 triggers ValueError in math.asin().
  2. Clamp pattern. Combining max() and min() keeps unit ratios inside [-1.0, 1.0].
  3. Clean right angle. After clamping, math.asin(1.0) converts smoothly to 90.0 degrees.

Frequently Asked Questions

Any real number x with -1 <= x <= 1. Anything outside that range raises ValueError.
It returns radians in [-pi/2, pi/2]. Pass the result to math.degrees() to get degrees in [-90, 90].
Floating-point arithmetic can leave a unit ratio slightly above 1.0 (like 1.0000000000000002). Clamp it with max(-1.0, min(1.0, val)) first.
No. Sine values repeat across quadrants, so asin returns only the principal branch from -90 to +90 degrees.
Use cmath.asin(x) from the cmath module.

Next: math.asinh()

Return the inverse hyperbolic sine of x as a float.

asinh() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful