Java Math atan() Method
The atan() method of Math class computes the trigonometric Arc Tangent (inverse of tangent ) of an angle. The value returned is between -pi/2 to pi/2.
Syntax:
public static double atan(double a)
Parameters:
The parameter ‘a’ represents the value whose arc tangent is to be determined.
Return Value:
The atan() method returns the arc tangent of the argument .
- It returns NaN, if we pass a NaN .
- If we pass zero as an argument, it will return zero with the same sign as the argument.
Example 1:
public class JavaMathAtanExample1 {
public static void main(String[] args) {
double a=30;
//return the arc tangent value for a
System.out.println("Arc tangent value : "+Math.atan(a));
}
}
Output:
Arc tangent value : 1.5374753309166493
Example 2:
public class JavaMathAtanExample2 {
public static void main(String[] args) {
//return the arc tangent value for Double.MIN_VALUE
double a=Double.MIN_VALUE;
System.out.println("Arc tangent value for "+a+" = "+Math.atan(a));
}
}
Output:
Arc tangent value for 4.9E-324 = 4.9E-324
Example 3:
public class JavaMathAtanExample3 {
public static void main(String[] args) {
double x = Math.PI;
System.out.println("Arc tangent value for "+x+" = "+Math.atan(x));
}
}
Output:
Arc tangent value for 3.141592653589793 = 1.2626272556789115
Example 4:
public class JavaMathAtanExample4 {
public static void main(String[] args) {
//return an arc tangent value for infinity
double x = 6/0.0d;
System.out.println("Arc tangent value for "+x+" = "+Math.atan(x));
}
}
Output:
Arc tangent value for Infinity = 1.5707963267948966
Example 5:
public class JavaMathAtanExample5 {
public static void main(String[] args) {
//return an arc tangent value for Nan
double x = 0.0d/0.0d;
System.out.println("Arc tangent value for "+x+" = "+Math.atan(x));
}
}
Output:
Arc tangent value for NaN = NaN
Example 6:
public class JavaMathAtanExample6 {
public static void main(String[] args) {
//return an arc tangent value for negative Infinity
double x = -90d/0.0d;
System.out.println("Arc tangent value for "" = "+Math.atan(x));
}
}
Output:
Arc tangent value for -Infinity = -1.5707963267948966
