Skip to main content

ATAN2

Description

Returns the arc tangent of 'y' / 'x'.

Syntax

ATAN2(<y>, <x>)

Parameters

ParameterDescription
<x>The value representing the horizontal distance (coordinate) from the origin (0,0) along the x-axis.
<y>The value representing the vertical distance (coordinate) from the origin (0,0) along the y-axis.

Return Value

The atan2 value of parameter y / x.

Special Cases

  • If y or x is NaN, returns NaN
  • If x > 0 and y = ±0.0, returns ±0 (sign follows y)
  • If x = 0.0 (either +0.0 or -0.0) and y > 0, returns π/2 (about 1.570796326794897)
  • If x = 0.0 (either +0.0 or -0.0) and y < 0, returns -π/2 (about -1.570796326794897)
  • If x < 0 and y = +0.0, returns π (about 3.141592653589793); if x < 0 and y = -0.0, returns -π
  • If y = +Infinity and x is finite, returns π/2; if y = -Infinity and x is finite, returns -π/2
  • If y = +Infinity and x = +Infinity, returns π/4 (about 0.7853981633974483)
  • If y = -Infinity and x = +Infinity, returns -π/4 (about -0.7853981633974483)
  • If y = +Infinity and x = -Infinity, returns 3π/4 (about 2.356194490192345)
  • If y = -Infinity and x = -Infinity, returns -3π/4 (about -2.356194490192345)
  • If x = +Infinity and finite y > 0, returns 0; if finite y < 0, returns -0
  • If x = -Infinity and finite y > 0, returns π; if finite y < 0, returns -π
  • If y or x is NULL, returns NULL

Examples

select atan2(0.1, 0.2);
+---------------------+
| atan2(0.1, 0.2) |
+---------------------+
| 0.46364760900080609 |
+---------------------+
select atan2(1.0, 1.0);
+---------------------+
| atan2(1.0, 1.0) |
+---------------------+
| 0.78539816339744828 |
+---------------------+
select atan2(cast('nan' as double), 1.0);
+----------------------------------+
| atan2(cast('nan' AS DOUBLE), 1.0)|
+----------------------------------+
| NaN |
+----------------------------------+
select atan2(1.0, cast('nan' as double));
+----------------------------------+
| atan2(1.0, cast('nan' AS DOUBLE))|
+----------------------------------+
| NaN |
+----------------------------------+
select atan2(0.0, 1.0);
+----------------+
| atan2(0.0, 1.0)|
+----------------+
| 0 |
+----------------+
select atan2(-0.0, 1.0);
+-----------------+
| atan2(-0.0, 1.0)|
+-----------------+
| -0 |
+-----------------+
select atan2(0.0, -1.0);
+-----------------+
| atan2(0.0, -1.0)|
+-----------------+
| 3.141592653589793|
+------------------+
select atan2(-0.0, -1.0);
+------------------+
| atan2(-0.0, -1.0)|
+------------------+
| -3.141592653589793|
+-------------------+
select atan2(1.0, 0.0);
+----------------+
| atan2(1.0, 0.0)|
+----------------+
| 1.570796326794897 |
+--------------------+
select atan2(-1.0, 0.0);
+-----------------+
| atan2(-1.0, 0.0)|
+-----------------+
| -1.570796326794897 |
+---------------------+
select atan2(cast('inf' as double), cast('-inf' as double));
+--------------------------------------------+
| atan2(cast('inf' AS DOUBLE), cast('-inf' AS DOUBLE)) |
+--------------------------------------------+
| 2.356194490192345 |
+--------------------------------------------+
select atan2(cast('-inf' as double), cast('inf' as double));
+-------------------------------------------+
| atan2(cast('-inf' AS DOUBLE), cast('inf' AS DOUBLE)) |
+-------------------------------------------+
| -0.7853981633974483 |
+-------------------------------------------+
select atan2(1.0, cast('-inf' as double));
+----------------------------------+
| atan2(1.0, cast('-inf' AS DOUBLE))|
+----------------------------------+
| 3.141592653589793 |
+----------------------------------+
select atan2(-1.0, cast('inf' as double));
+---------------------------------+
| atan2(-1.0, cast('inf' AS DOUBLE))|
+---------------------------------+
| -0 |
+---------------------------------+