ATAN2
描述
返回 'y' / 'x' 的反正切。
语法
ATAN2(<y>, <x>)
参数
参数 | 说明 |
---|---|
<x> | 参与计算的反正切的值,表示水平坐标(或 x 值),从原点 (0,0) 沿 x 轴的距离。 |
<y> | 参与计算的反正切的值,表示垂直坐标(或 y 值),从原点 (0,0) 沿 y 轴的距离。 |
返回值
参数 y / x 的反正切值
特殊情况
- 若
y
或x
为NaN
,返回NaN
- 当
x > 0
且y = ±0.0
,返回±0
(符号同y
) - 当
x = 0.0
(含+0.0
与-0.0
)且y > 0
,返回π/2
(约 1.570796326794897) - 当
x = 0.0
(含+0.0
与-0.0
)且y < 0
,返回-π/2
(约 -1.570796326794897) - 当
x < 0
且y = +0.0
,返回π
(约 3.141592653589793);当x < 0
且y = -0.0
,返回-π
- 当
y = +∞
、x
有限,返回π/2
;当y = -∞
、x
有限,返回-π/2
- 当
y = +∞
且x = +∞
,返回π/4
(约 0.7853981633974483) - 当
y = -∞
且x = +∞
,返回-π/4
(约 -0.7853981633974483) - 当
y = +∞
且x = -∞
,返回3π/4
(约 2.356194490192345) - 当
y = -∞
且x = -∞
,返回-3π/4
(约 -2.356194490192345) - 当
x = +∞
且y
有限为正,返回0
;当x = +∞
且y
有限为负,返回-0
- 当
x = -∞
且y
有限为正,返回π
;当x = -∞
且y
有限为负,返回-π
- 当
y
或x
为NULL
,返回NULL
举例
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 |
+---------------------------------+