![]() |
VOOZH | about |
The Math.atan() method in Java is used to calculate the arc tangent of a given value. This method is part of the java.lang.Math package. In this article, we are going to discuss the working of this method with regular values and for special cases such as infinity and NaN. This method is very useful when we have to work with angles.
Special Cases:
The syntax of the atan() method is:
public static double atan(double a)
Now, we are going to discuss some examples for better understanding.
Example 1: In this example, we will see the basic usage of the Math.atan() method.
Output:
Explanation: In the above example, we are calculating the atan for different types of values.
Example 2: In this example, we will use atan() method to handle infinity and NaN.
atan(+Infinity) = 1.5707963267948966 atan(-Infinity) = -1.5707963267948966 atan(NaN) = NaN atan(0.0 / 0.0) = NaN
Explanation: In the above example, we are handling the cases where the input value is positive infinity and negative infinity and NaN.