ATAN
Description
Return the arctangent value.
-
When there is only one parameter: Return the arctangent of
x, with the result range of [-π/2, π/2] -
When there are two parameters: Return the arctangent of
y/x, with the same behavior as ATAN2(y, x), with the result range of [-π, π]
Syntax
ATAN([<y>, ]<x>)
Parameters
| Parameter | Description |
|---|---|
<x> | When there is only one parameter, it indicates the value that needs to be calculated as the arctangent; when there are two parameters, it indicates the horizontal coordinate (or x-value), the distance along the x-axis from the origin (0,0). |
<y> | Optional, representing the vertical coordinate (or y-value), the distance along the y-axis from the origin (0,0) |
Return Value
The atan value of parameter x.
Special Cases
Single-parameter version
- When
xis NaN, returns NaN - When
xis positive infinity, returns π/2 (approximately 1.570796326794897) - When
xis negative infinity, returns -π/2 (approximately -1.570796326794897) - When
xis NULL, returns NULL
Two-parameter version
- If
yorxis NaN, returns NaN - If
x > 0andy = ±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 < 0andy = +0.0, returns π (about 3.141592653589793); ifx < 0andy = -0.0, returns -π - If
y = +Infinityandxis finite, returns π/2; ify = -Infinityandxis finite, returns -π/2 - If
y = +Infinityandx = +Infinity, returns π/4 (about 0.7853981633974483) - If
y = -Infinityandx = +Infinity, returns -π/4 (about -0.7853981633974483) - If
y = +Infinityandx = -Infinity, returns 3π/4 (about 2.356194490192345) - If
y = -Infinityandx = -Infinity, returns -3π/4 (about -2.356194490192345) - If
x = +Infinityand finitey> 0, returns 0; if finitey< 0, returns -0 - If
x = -Infinityand finitey> 0, returns π; if finitey< 0, returns -π - If
yorxis NULL, returns NULL
Examples
select atan(0);
+-----------+
| atan(0.0) |
+-----------+
| 0 |
+-----------+
select atan(2);
+--------------------+
| atan(2.0) |
+--------------------+
| 1.1071487177940904 |
+--------------------+
select atan(cast('nan' as double));
+-----------------------------+
| atan(cast('nan' AS DOUBLE)) |
+-----------------------------+
| NaN |
+-----------------------------+
select atan(cast('inf' as double));
+-----------------------------+
| atan(cast('inf' AS DOUBLE)) |
+-----------------------------+
| 1.570796326794897 |
+-----------------------------+
select atan(cast('-inf' as double));
+------------------------------+
| atan(cast('-inf' AS DOUBLE)) |
+------------------------------+
| -1.570796326794897 |
+------------------------------+