ATAN2
Description
Returns the arc tangent of 'y' / 'x'.
Syntax
ATAN2(<y>, <x>)
Parameters
Parameter | Description |
---|---|
<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
orx
is NaN, returns NaN - If
x > 0
andy = ±0.0
, returns ±0 (sign followsy
) - If
x = 0.0
(either +0.0 or -0.0) andy > 0
, returns π/2 (about 1.570796326794897) - If
x = 0.0
(either +0.0 or -0.0) andy < 0
, returns -π/2 (about -1.570796326794897) - If
x < 0
andy = +0.0
, returns π (about 3.141592653589793); ifx < 0
andy = -0.0
, returns -π - If
y = +Infinity
andx
is finite, returns π/2; ify = -Infinity
andx
is finite, returns -π/2 - If
y = +Infinity
andx = +Infinity
, returns π/4 (about 0.7853981633974483) - If
y = -Infinity
andx = +Infinity
, returns -π/4 (about -0.7853981633974483) - If
y = +Infinity
andx = -Infinity
, returns 3π/4 (about 2.356194490192345) - If
y = -Infinity
andx = -Infinity
, returns -3π/4 (about -2.356194490192345) - If
x = +Infinity
and finitey
> 0, returns 0; if finitey
< 0, returns -0 - If
x = -Infinity
and finitey
> 0, returns π; if finitey
< 0, returns -π - If
y
orx
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 |
+---------------------------------+