SQL Tutorial SQL Advanced SQL Database SQL References

MySQL ATAN2() Function



The MySQL ATAN2() function returns arc tangent of two numbers. This function uses sign of both numbers to determine the quadrant for the result.

Syntax

ATAN2(y, x)

Parameters

y Required. Specify the first number used to calculate the arc tangent.
x Required. Specify the second number used to calculate the arc tangent.

Return Value

Returns the arc tangent of two numbers.

Example 1:

The example below shows the usage of ATAN2() function.

mysql> SELECT ATAN2(PI(), 2);
Result: 1.0038848218538872

mysql> SELECT ATAN2(3, 5);
Result: 0.5404195002705842

mysql> SELECT ATAN2(2, 2);
Result: 0.7853981633974483

mysql> SELECT ATAN2(2, -2);
Result: 2.356194490192345

mysql> SELECT ATAN2(-2, 2);
Result: -0.7853981633974483

mysql> SELECT ATAN2(-2, -2);
Result: -2.356194490192345

Example 2:

Consider a database table called Sample with the following records:

Datayx
Data 11010
Data 2-1010
Data 310-10
Data 4-10-10

To calculate the arc tangent of records of column y and column x, the following query can be used:

SELECT *, ATAN2(y, x) AS ATAN2_Value FROM Sample;

This will produce the result as shown below:

DatayxATAN2_Value
Data 110100.7853981633974483
Data 2-1010-0.7853981633974483
Data 310-102.356194490192345
Data 4-10-10-2.356194490192345

❮ MySQL Functions