atan2, atan2f, atan2l
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<math.h>
|
||
|
float
atan2f
(
float
y,
float
x
)
;
|
(1) | (C99 起) |
|
double
atan2
(
double
y,
double
x
)
;
|
(2) | |
|
long
double
atan2l
(
long
double
y,
long
double
x
)
;
|
(3) | (C99 起) |
|
_Decimal32 atan2d32
(
_Decimal32 y, _Decimal32 x
)
;
|
(4) | (C23 起) |
|
_Decimal64 atan2d64
(
_Decimal64 y, _Decimal64 x
)
;
|
(5) | (C23 起) |
|
_Decimal128 atan2d128
(
_Decimal128 y, _Decimal128 x
)
;
|
(6) | (C23 起) |
|
定义于头文件
<tgmath.h>
|
||
|
#define atan2( y, x )
|
(7) | (C99 起) |
atan2l
);否则,若任一参数具有整数类型或类型为
double
,则调用
(2)
(
atan2
);否则调用
(1)
(
atan2f
)。
|
当且仅当实现预定义了
|
(since C23) |
目录 |
参数
| x, y | - | 浮点数值 |
返回值
If no errors occur, the arc tangent of y / x ( arctan(| y |
| x |
如果发生定义域错误,则返回一个实现定义的值。
如果由于下溢发生范围错误,将返回正确结果(舍入后)。
错误处理
错误报告方式遵循
math_errhandling
中的规范。
当 x 和 y 同时为零时可能出现定义域错误。
如果实现支持 IEEE 浮点算术 (IEC 60559):
- 如果 x 和 y 均为零,则 不会 发生定义域错误;
- 如果 x 和 y 均为零,则也不会发生值域错误;
- 如果 y 为零,则不会发生极点错误;
-
如果
y
为
±0且 x 为负数或-0,则返回±π; -
如果
y
为
±0且 x 为正数或+0,则返回±0; -
如果
y
为
±∞且 x 为有限值,则返回±π/2; -
如果
y
为
±∞且 x 为-∞,则返回±3π/4; -
如果
y
为
±∞且 x 为+∞,则返回±π/4; -
如果
x
为
±0且 y 为负数,则返回-π/2; -
如果
x
为
±0且 y 为正数,则返回+π/2; -
如果
x
为
-∞且 y 为有限正值,则返回+π; -
如果
x
为
-∞且 y 为有限负值,则返回-π; -
如果
x
为
+∞且 y 为有限正值,则返回+0; -
如果
x
为
+∞且 y 为有限负值,则返回-0; - 如果 x 或 y 为 NaN,则返回 NaN。
注释
atan2 ( y, x ) 等价于 carg ( x + I * y ) 。
POSIX 规范 规定,在下溢情况下,将返回 y / x 的值;若不支持此操作,则返回一个不大于 DBL_MIN 、 FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
#include <math.h> #include <stdio.h> int main(void) { // 常规用法:两个参数的符号决定象限 // atan2(1,1) = +pi/4,第一象限 printf("(+1,+1) cartesian is (%f,%f) polar\n", hypot( 1, 1), atan2( 1, 1)); // atan2(1, -1) = +3pi/4,第二象限 printf("(+1,-1) cartesian is (%f,%f) polar\n", hypot( 1,-1), atan2( 1,-1)); // atan2(-1,-1) = -3pi/4,第三象限 printf("(-1,-1) cartesian is (%f,%f) polar\n", hypot(-1,-1), atan2(-1,-1)); // atan2(-1,-1) = -pi/4,第四象限 printf("(-1,+1) cartesian is (%f,%f) polar\n", hypot(-1, 1), atan2(-1, 1)); // 特殊值 printf("atan2(0, 0) = %f atan2(0, -0)=%f\n", atan2(0,0), atan2(0,-0.0)); printf("atan2(7, 0) = %f atan2(7, -0)=%f\n", atan2(7,0), atan2(7,-0.0)); }
输出:
(+1,+1) cartesian is (1.414214,0.785398) polar (+1,-1) cartesian is (1.414214,2.356194) polar (-1,-1) cartesian is (1.414214,-2.356194) polar (-1,+1) cartesian is (1.414214,-0.785398) polar atan2(0, 0) = 0.000000 atan2(0, -0)=3.141593 atan2(7, 0) = 1.570796 atan2(7, -0)=1.570796
参考文献
- C23 标准 (ISO/IEC 9899:2024):
-
- 7.12.4.4 atan2 函数 (p: TBD)
-
- 7.25 类型通用数学 <tgmath.h> (p: TBD)
-
- F.10.1.4 atan2 函数 (p: TBD)
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.12.4.4 atan2 函数 (p: 174)
-
- 7.25 泛型数学 <tgmath.h> (p: 272-273)
-
- F.10.1.4 atan2 函数 (p: 378)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.12.4.4 atan2 函数 (p: 239)
-
- 7.25 泛型数学 <tgmath.h> (p: 373-375)
-
- F.10.1.4 atan2 函数 (p: 519)
- C99标准(ISO/IEC 9899:1999):
-
- 7.12.4.4 atan2函数(第219页)
-
- 7.22 泛型数学 <tgmath.h>(第335-337页)
-
- F.9.1.4 atan2函数(第456页)
- C89/C90 标准 (ISO/IEC 9899:1990):
-
- 4.5.2.4 atan2 函数
参见
|
(C99)
(C99)
|
计算反正弦(
\({\small\arcsin{x} }\)
arcsin(x)
)
(函数) |
|
(C99)
(C99)
|
计算反余弦(
\({\small\arccos{x} }\)
arccos(x)
)
(函数) |
|
(C99)
(C99)
|
计算反正切(
\({\small\arctan{x} }\)
arctan(x)
)
(函数) |
|
(C99)
(C99)
(C99)
|
计算复数的相位角
(函数) |
|
C++ 文档
关于
atan2
|
|