What is Math.atan() in Java?

Java has a built-in Math class, defined in the java.lang package, which contains important functions to perform basic mathematical operations.

The class has the atan() method, which is used to compute an arctan\arctan or tan1\tan^{-1} (pronounced as “inverse tangent”) of the specified value.

If tan(θ)tan(\theta) is x then tan1tan^{-1}(x) or arctan(x)arctan(x) is θ\theta.

Method definition

public  static double atan(double value);

Parameter

value represents the double value for which we have to find the arc tangent.

Return value

The function returns the double value corresponding to the arctangent of the value. The returned value will lie within the range π/2\pi/2 to π/2-\pi/2.

Note: Math.PI is a constant equivalent to π\pi in Mathematics.

If the value is infinity or NaNnot a number, then the returned value is NaN.

Note: To convert an angle measured in radians to an equivalent angle measured in degrees and vice versa, you can use the built-in Math.toDegrees(double angle_in_randians) and Math.toRadians(double angle_in_degrees) methods.

Code

class HelloWorld {
public static void main( String args[] ) {
double result = Math.atan(1);
System.out.println("atan(1) = " + result);
result = Math.atan(0);
System.out.println("atan(0) = " + result);
result = Math.atan(0.48);
System.out.println("atan(0.48) = " + result);
result = Math.atan(0.66);
System.out.println("atan(O.66) = " + result);
result = Math.atan(0.8);
System.out.println("atan(0.8) = " + result);
result = Math.atan(1);
System.out.println("atan(1) = " + result);
result = Math.atan(Double.NaN);
System.out.println("atan(NaN) = " + result);
result = Math.atan(Double.POSITIVE_INFINITY);
System.out.println("atan(∞) = " + result);
}
}

Free Resources