Java Math asin()

The arcsine is the inverse of the sine function.

The syntax of the asin() method is:

Math.asin(double num)

Here, asin() is a static method. Hence, we are accessing the method using the class name, Math.


asin() Parameters

The asin() method takes a single parameter.

  • num - number whose arc sine is to be returned

Note: The absolute value of num should be always less than 1.


asin() Return Value

  • returns the arcsine of the specified number
  • returns 0 if the specified value is zero
  • returns NaN if the specified number is NaN or greater than 1

Note: The returned value is an angle between -pi/2 to pi/2.


Example 1: Java Math asin()

In the above example, we have imported the java.lang.Math package. This is important if we want to use methods of the Math class. Notice the expression,

Math.asin(a)

Here, we have directly used the class name to call the method. It is because asin() is a static method.


Example 2: Math asin() Returns NaN

Here, we have created two variables named a and b.

  • Math.asin(a) - returns NaN because value of a is greater than 1
  • Math.asin(b) - returns NaN because square root of a negative number (-5) is not a number

Note: We have used the Java Math.sqrt() method to compute the square root of a number.