The arc tangent is the inverse of the tangent function.
The syntax of the atan() method is:
Math.atan(double num)
Here, atan() is a static method. Hence, we are accessing the method using the class name, Math.
atan() Parameters
The atan() method takes a single parameter.
- num - number whose inverse tangent function is to be returned
atan() Return Value
- returns the inverse tangent of the specified number
- returns 0 if the specified value is zero
- returns
NaNif the specified number isNaN
Note: The returned value is an angle between -pi/2 to pi/2.
Example 1: Java Math atan()
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.atan(a)
Here, we have directly used the class name to call the method. It is because atan() is a static method.
Example 2: Math atan() Returns NaN
Here, we have created a variable named a.
- Math.atan(a) - 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.