Skip to content

ATAN2

Returns the inverse tangent (arc tangent) of the angle from a ray defined by n and m to the X-axis.

If m > 0, ATAN2(n, m) returns the same result as ATAN(n/m).

Represents the angle between:

  • The X-axis
  • The ray from the point (0,0) to the point (n, m) (if n and m are not both 0).

Syntax

sql
ATAN2(n, m)

Arguments

n: Y-coordinate of the point at the end of the ray as DECIMAL or another data type that can be converted to a numeric data type.


m: X-coordinate of the point at the end of the ray as DECIMAL or another data type that can be converted to a numeric data type.

Return Value

A DECIMAL value in radians (not degrees) in the range [-π, +π].

Notes

  • Arguments provided in a numeric form other than DECIMA are converted to DECIMAL.
  • String arguments are converted to DECIMAL if possible.
  • Other data types for the arguments will result in an error.
  • If either argument is NULL, NULL is returned.

Example

sql
SELECT  atan2(NULL, 5), 
        atan2(0, 5), 
        atan2('0', '5'), 
        atan2(0.7425, 5), 
        atan2(22.4, 5);
txt
+----------------+-------------+-----------------+------------------+----------------+
| ATAN2(NULL, 5) | ATAN2(0, 5) | ATAN2('0', '5') | ATAN2(0.7425, 5) | ATAN2(22.4, 5) |
+----------------+-------------+-----------------+------------------+----------------+
| NULL           | 0           | 0               | 0.14...          | 1.35...        |
+----------------+-------------+-----------------+------------------+----------------+
sql
SELECT  atan2(-0.34, 5),
        atan2(1000,5000),
        atan2(500,2500),
        atan2(90381.56, 100000);
txt
+-----------------+------------------+-----------------+-------------------------+
| ATAN2(-0.34, 5) | ATAN2(1000,5000) | ATAN2(500,2500) | ATAN2(90381.56, 100000) |
+-----------------+------------------+-----------------+-------------------------+
| -0.06...        | 0.19...          | 0.19...         | 0.73...                 |
+-----------------+------------------+-----------------+-------------------------+