跳到主要内容
版本:26.x

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 |
+---------------------------------+