MySQL ASIN() Function
MySQL ASIN() Function: Calculating Arcsine Angles in SQL
The ASIN() function computes the arc sine (inverse sine) of a numeric value in MySQL. It accepts a sine ratio from -1 to 1 and returns the matching angle in radians between -PI()/2 and PI()/2.
Engineers use ASIN() inside Haversine geolocation queries to compute great-circle distances between shipping origins and customer addresses. Like other trigonometric functions in MySQL, ASIN() returns a floating-point DOUBLE value.
Syntax
ASIN(x)
x: A numeric value between-1and1. Values outside that range returnNULL.
Practical Example
Suppose demo_orders records warehouse conveyor incline ratios (rise_ratio) for package routing lanes. You want to inspect the ramp angle in both radians and degrees for safety compliance.
SELECT
order_id,
lane_code,
rise_ratio,
ROUND(ASIN(rise_ratio), 4) AS radians_val,
ROUND(DEGREES(ASIN(rise_ratio)), 2) AS slope_degrees
FROM demo_orders
WHERE rise_ratio IS NOT NULL;
| order_id | lane_code | rise_ratio | radians_val | slope_degrees |
|---|---|---|---|---|
| 501 | L-01 | 0.00 | 0.0000 | 0.00 |
| 502 | L-02 | 0.50 | 0.5236 | 30.00 |
| 503 | L-03 | 1.25 | NULL | NULL |
Lane L-02 has a sine ratio of 0.50, giving 30.00 degrees. Row 503 holds 1.25, which exceeds 1, so ASIN(1.25) produces NULL.
Common Mistakes & NULL Behavior
- Inputs outside [-1, 1]: Calling
ASIN(2)orASIN(-1.5)returnsNULLinstead of raising an exception. Always validate sensor or formula outputs before passing them in. - Unclamped Haversine square roots: When computing
2 * ASIN(SQRT(a)), floating-point inaccuracies can pushaslightly past1.0. UseASIN(SQRT(LEAST(1.0, a)))to prevent unexpectedNULLdistances. - Expecting degrees directly:
ASIN()outputs radians, not degrees. PassingASIN(0.5)straight into a UI expecting degrees displays0.5236instead of30.
Frequently Asked Questions
What is the valid input range for MySQL ASIN()?
MySQL ASIN(x) accepts numbers from -1 through 1 inclusive. Any input below -1 or above 1 returns NULL.
What does ASIN(NULL) return?
ASIN(NULL) returns NULL. Combine it with COALESCE() or WHERE col IS NOT NULL when summarizing results.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.