Java Math asin() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.lang.Math

Definition

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
CallWhat 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

ParameterDescription
aThe value whose arc sine you want. It must be in the range -1.0 to 1.0.

Return Value

Return ValueDescription
doubleThe 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.

Compare with Similar Methods

The inverse trigonometry family:

MethodHow it differs
acos(x)Arc cosine: result from 0 to PI; same domain -1 to 1.
atan(x)Arc tangent: accepts any number, result between -PI/2 and PI/2.
atan2(y, x)Angle from two sides, any quadrant, no domain problems.
sin(a)The forward function: asin reverses it.

Java Examples

Example 1 — Arc Sine at -1, 0, 0.5, and 1

Print the angles that go with a few simple sine values, and show one of them in degrees.

Java
import java.util.Locale;

public class MathAsinBasics {
    public static void main(String[] args) {
        System.out.println("asin(0.0)  = " + Math.asin(0.0));
        System.out.println("asin(1.0)  = " + Math.asin(1.0));
        System.out.println("asin(-1.0) = " + Math.asin(-1.0));
        double half = Math.toDegrees(Math.asin(0.5));
        System.out.println("asin(0.5) in degrees = " + String.format(Locale.US, "%.2f", half));
    }
}

How It Works

  1. Zero maps to zero. The angle whose sine is 0 is 0 radians, so asin(0.0) prints 0.0.
  2. 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.
  3. 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.

Java
public class MathAsinDomain {
    public static void main(String[] args) {
        System.out.println("asin(1.5)  = " + Math.asin(1.5));
        System.out.println("asin(-2.0) = " + Math.asin(-2.0));
        System.out.println("asin(NaN)  = " + Math.asin(Double.NaN));

        double ratio = (0.1 + 0.2) / 0.3;
        System.out.println("ratio = " + ratio);
        System.out.println("asin(ratio) = " + Math.asin(ratio));
        double safe = Math.max(-1.0, Math.min(1.0, ratio));
        System.out.println("asin(clamped) = " + Math.asin(safe));
    }
}

How It Works

  1. 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.
  2. 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.
  3. 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");
            }
        }
    }
}

How It Works

  1. 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.
  2. 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.
  3. 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.

Next: atan()

Arc tangent: the angle in radians (-pi/2 to pi/2) whose tangent is the given value.

atan() tutorial →

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.

11 people found this page helpful