Java Math.atan() method returns arc tangent of the given value. Arc tangent is the inverse of tangent function. The value returned by this method ranges between -pi/2 and pi/2.
public class JavaExample
{
public static void main(String[] args)
{
double a = 0.0;
System.out.println(Math.atan(a));
}
}
Output:
0.0
Syntax of Math.atan() method
Math.atan(1); //returns 0.7853981633974483
atan() Description
public static double atan(double a): It returns arc tangent of the given value (argument).
atan() Parameters
- a: A double value whose arc tangent is to be determined.
atan() Return Value
- Returns arc tangent of the argument
a. - If the argument is NaN (Not a number), then it returns NaN.
- If the argument is zero, then it returns zero with the same sign.
Example 1
public class JavaExample
{
public static void main(String[] args)
{
double d1 = 1.0;
double d2 = 0;
double d3 = -1.0;
System.out.println(Math.atan(d1));
System.out.println(Math.atan(d2));
System.out.println(Math.atan(d3));
}
}
Output:

Example 2
public class JavaExample
{
public static void main(String[] args)
{
double d1 = Double.MAX_VALUE;
double d2 = Double.MIN_VALUE;
double d3 = 0.0/0; //NaN
System.out.println(Math.atan(d1));
System.out.println(Math.atan(d2));
System.out.println(Math.atan(d3));
}
}
Output:

Example 3
public class JavaExample
{
public static void main(String[] args)
{
double d1 = Double.POSITIVE_INFINITY;
double d2 = Double.NEGATIVE_INFINITY;
double d3 = Math.PI;
System.out.println(Math.atan(d1));
System.out.println(Math.atan(d2));
System.out.println(Math.atan(d3));
}
}
Output:
