Java Math asin()

asin() accepts double value as an argument and returns arc sine of the argument value. The returned value is also of type double.

If the argument is NaN or its absolute value is greater than 1, then asin() returns NaN.

Following is the syntax of asin() method.

</>
Copy
double radians = asin(double value)

Example 1 – Math.asin(double)

In the following example, we pass a double value within the range [-1, 1] as argument to asin() method and find its value.

Java Program

</>
Copy
public class MathExample {
	public static void main(String[] args) {
		double x = 0.5;
		double a = Math.asin(x);
		System.out.println(a+" radians");
	}
}

Output

0.5235987755982989 radians

Example 2 – Math.asin() – Argument Value that is Out of Valid Range

In the following example, we pass a double value outside of the range [-1, 1] as argument to asin() method. As per the definition of the function, it should return NaN value.

Java Program

</>
Copy
public class MathExample {
	public static void main(String[] args) {
		double x = 3;
		double a = Math.asin(x);
		System.out.println(a);
	}
}

Output

NaN

Example 3 – Math.asin(NaN)

In the following example, we pass Double.NaN as argument to asin() method. As per the definition of the function, asin() should return NaN value.

Java Program

</>
Copy
public class MathExample {
	public static void main(String[] args) {
		double x = Double.NaN;
		double a = Math.asin(x);
		System.out.println(a);
	}
}

Output

NaN

Conclusion

In this Java Tutorial, we learned about Java Math.asin() function, with example programs.