In Java, Math.asin(x) returns the arc sine of x: the angle, in radians, whose sine is x. It undoes Math.sin. Math.asin(1) is 1.5707963267948966, a quarter turn.
The result is always between -PI/2 and PI/2 (-90 to 90 degrees). Use it when you know the ratio opposite / hypotenuse of a right triangle, for example the angle of a ladder, a ramp, or a ray of light.
A static method of the java.lang.Math class, available since the early versions of Java (JDK 1.0). Call it on the class name, as in Math.asin(...). No import is needed, because classes in java.lang are always visible.
Syntax
Pass a double from -1.0 to 1.0. The angle comes back in radians.
Java
double a = Math.asin(1.0); // 1.5707963267948966
double b = Math.asin(0.0); // 0.0
double deg = Math.toDegrees(Math.asin(0.5)); // about 30.0
double bad = Math.asin(1.5); // NaN
Call
What it does
Math.asin(1.0)
Returns PI/2 (1.5707963267948966).
Math.asin(-1.0)
Returns -PI/2.
Math.asin(0.5)
Returns about 0.5236 radians (30 degrees).
Math.asin(1.5)
Outside the domain: returns NaN.
There is only a double version. To see the answer in degrees, wrap the call: Math.toDegrees(Math.asin(x)).
Library declarations
Java
// java.lang.Math
public static double asin(double a)
Parameters
Parameter
Description
a
The value whose arc sine you want. It must be in the range -1.0 to 1.0.
Return Value
Return Value
Description
double
The angle in radians, in the range -PI/2 to PI/2. The result is NaN if a is NaN or its absolute value is greater than 1. For a zero argument the result is a zero with the same sign.
Zero maps to zero. The angle whose sine is 0 is 0 radians, so asin(0.0) prints 0.0.
The two limits. A sine of 1 happens at the top of the wave, a quarter turn (PI/2); a sine of -1 is the bottom, minus a quarter turn. These are the ends of the result range.
Radians to degrees. The angle for sine 0.5 is about 0.5236 radians; toDegrees turns that into 30 degrees, and %.2f hides the last-digit noise to print 30.00.
Example 2 — Out of Range Gives NaN: Clamp the Input
Look at inputs outside -1 to 1, and at a rounding error that sends a "perfect" ratio just over 1.
asin(1.5) = NaN
asin(-2.0) = NaN
asin(NaN) = NaN
ratio = 1.0000000000000002
asin(ratio) = NaN
asin(clamped) = 1.5707963267948966
How It Works
No such angle. A sine can never be 1.5 or -2.0, so Java returns NaN instead of throwing an exception, and a NaN input also stays NaN.
A ratio that is "1" but not quite. 0.1 + 0.2 is 0.30000000000000004, so dividing by 0.3 gives 1.0000000000000002, just past the allowed limit, and the arc sine is NaN.
Clamp, then call.Math.min(1.0, ratio) pulls the value back to exactly 1.0, and Math.max(-1.0, ...) guards the other end, so the call returns the quarter turn.
Example 3 — At What Angle Does a 5 m Ladder Lean?
The ladder's length is the hypotenuse and the height it reaches is the opposite side, so the angle is asin(height / length). A height above the length is impossible.
Java
import java.util.Locale;
public class MathAsinLadder {
public static void main(String[] args) {
double length = 5.0;
double[] heights = {2.5, 4.0, 4.5, 6.0};
for (double h : heights) {
double angle = Math.toDegrees(Math.asin(h / length));
if (Double.isNaN(angle)) {
System.out.println("Reach " + h + " m: ladder too short");
} else {
System.out.println("Reach " + h + " m: " + String.format(Locale.US, "%.2f", angle) + " degrees");
}
}
}
}
Half the length. Reaching 2.5 m with a 5 m ladder means a sine of 0.5, which is a 30 degree angle with the ground.
A 3-4-5 triangle. Reaching 4.0 m gives a ratio of 0.8, the 3-4-5 right triangle, with an angle of about 53.13 degrees; reaching higher makes the ladder steeper, 64.16 degrees at 4.5 m.
Detecting the impossible. 6.0 / 5.0 is 1.2, outside the domain, so the arc sine is NaN; Double.isNaN turns that into a useful message.
Frequently Asked Questions
It returns the arc sine of a value from -1 to 1: the angle in radians, between -PI/2 and PI/2, whose sine is that value. Math.asin(1) is 1.5707963267948966.
NaN. No exception is thrown. Check the value first, or test the result with Double.isNaN.
A calculation such as (0.1 + 0.2) / 0.3 gives 1.0000000000000002, just over the limit. Clamp the input with Math.max(-1.0, Math.min(1.0, x)) before calling asin.
Wrap it with Math.toDegrees: Math.toDegrees(Math.asin(0.5)) is about 30.0. Round it for display, because the last digit can be off.
sin takes an angle in radians and returns a ratio from -1 to 1. asin takes that ratio and returns the angle. They undo each other within the range -PI/2 to PI/2.