Java Math atan()

atan() accepts double value as an argument and returns arc tangent of the argument value. The returned value is also of type double.

If the argument is NaN, then atan() returns NaN.

Following is the syntax of atan() method.

double radians = atan(double value)

Example 1 – Math.atan(double)

In the following example, we pass a double value within the range [-infinity, infinity] as argument to atan() method and find its value.

Java Program

public class MathExample {
	public static void main(String[] args) {
		double x = 51;
		double a = Math.atan(x);
		System.out.println(a+" radians");
	}
}

Output

1.551190995937692 radians
ADVERTISEMENT

Example 2 – Math.atan(Double.MAX_VALUE) – Positive Infinity

In the following example, we pass maximum value for a double as argument to atan() method. Double. MAX_VALUE should act like an infinity. And we would get an angle of approximately 90 degrees which is very near to 1.5708 radians.

Java Program

public class MathExample {
	public static void main(String[] args) {
		double x = Double.MAX_VALUE;
		double a = Math.atan(x);
		System.out.println(a+" radians");
	}
}

Output

1.5707963267948966 radians

Example 3 – Math.atan(-Double.MAX_VALUE) – Negative Infinity

In the following example, we pass negation of maximum value for a double as argument to atan() method. MAX_VALUE should act like negative infinity. And we would get an angle of approximately -90 degrees which is very near to -1.5708 radians.

Java Program

public class MathExample {
	public static void main(String[] args) {
		double x = -Double.MAX_VALUE;
		double a = Math.atan(x);
		System.out.println(a+" radians");
	}
}

Output

-1.5707963267948966 radians

Example 4 – Math.atan(NaN)

In the following example, we pass Double.NaN as argument to atan() method. As per the definition of the function, atan() should return NaN value.

Java Program

public class MathExample {
	public static void main(String[] args) {
		double x = Double.NaN;
		double a = Math.atan(x);
		System.out.println(a);
	}
}

Output

NaN

Conclusion

In this Java Tutorial, we learned about Java Math.atan() function, with example programs.