# Java Math atan2() Method

by

The atan2() method of Math class returns an angle theta from the conversion of rectangular coordinates to polar coordinates.

Syntax:

public static double atan2(double y, double x)

Parameters:

The parameter ‘y’ represents the ordinate coordinate whereas ‘x’ represents the abscissa coordinate.

Return Value:

The atan2() method returns the angle theta from the conversion of rectangular coordinate to polar coordinate. Special cases of atan2() method are as follows:

• It returns NaN, if either argument is NaN.
• If returns positive zero, if the first argument is positive and finite and the second argument is positive infinity.
• It returns negative zero, if the first argument is negative and finite and the second argument is positive infinity.
• It returns the double value closest to pi, if the first argument is positive and finite and the second argument is negative infinity.
• It returns the double value closest to -pi, if the first argument is negative and finite and the second argument is negative infinity.
• It returns the double value closest to pi/2, if the first argument is positive infinity and the second argument is finite.
• It returns the double value closest to -pi/2, if the first argument is negative infinity and the second argument is finite.
• It returns the double value closest to pi/4, if the arguments are positive infinity.
• It returns the double value closest to -3*pi/4, if the arguments are negative infinity.
• It returns the double value closest to 3*pi/4, if the first argument is positive infinity and the second argument is negative infinity.
• It returns the double value closest to -pi/4, if the first argument is negative infinity and the second argument is positive infinity.

Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Example 5:

Output:

Example 6:

Output:

by