atan2
计算y/x的反正切的弧度值。
接口定义
C interface:
float atan2f(float y, float x);
double atan2(double y, double x);
long double atan2l(long double y, long double x);
Fortran interface:
RES = ATAN2F(Y,X);
RES = ATAN2(Y,X);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
y |
|
代表y轴坐标的浮点值。 |
输入 |
x |
|
代表x轴坐标的浮点值。 |
输入 |
返回值
对于atan2(y, x)来说,返回的是原点至点(x, y)的方位角,即与x轴的夹角。返回值的单位为弧度,取值范围为(-π, +π]。
- 输入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为nan,或y为nan,则返回nan。
依赖
C: "km.h"
示例
C interface:
double pi = acos(-1); // typical usage double x1 = 1.0, y1 = pi/2, x2 = -3*pi/4, y2 = 2.0; double x3 = 4.0, y3 = -4.0, x4 = -3.0, y4 = 3.0; // special handling double a = 0.0, b = INFINITY, c = -INFINITY, d = NAN; // print result printf("atan2(pi/2, 1.0) = %.15f\n", atan2(y1, x1)); printf("atan2(2.0, -3*pi/4) = %.15f\n", atan2(y2, x2)); printf("atan2(-4.0, 4.0) = %.15f\n", atan2(y3, x3)); printf("atan2(3.0, -3.0) = %.15f\n", atan2(y4, x4)); printf("atan2(+0.0, +0.0) = %+.15f\n", atan2(a, a)); printf("atan2(+0.0, -0.0) = %+.15f\n", atan2(a, -a)); printf("atan2(-0.0, +0.0) = %+.15f\n", atan2(-a, a)); printf("atan2(-0.0, -0.0) = %+.15f\n", atan2(-a, -a)); printf("atan2(+0.0, -4.0) = %+.15f\n", atan2(a, y3)); printf("atan2(-0.0, +3.0) = %+.15f\n", atan2(-a, y4)); printf("atan2(-4.0, +0.0) = %+.15f\n", atan2(y3, a)); printf("atan2(+3.0, -0.0) = %+.15f\n", atan2(y4, -a)); printf("atan2(INFINITY, 1.0) = %+.15f\n", atan2(b, x1)); printf("atan2(-INFINITY, -1.0) = %+.15f\n", atan2(c, -x1)); printf("atan2(1.0, -INFINITY) = %+.15f\n", atan2(x1, c)); printf("atan2(-3.0, -INFINITY) = %+.15f\n", atan2(x4, c)); printf("atan2(1.0, INFINITY) = %+.15f\n", atan2(x1, b)); printf("atan2(-3.0, INFINITY) = %+.15f\n", atan2(x4, b)); printf("atan2(1.0, NAN) = %+.15f\n", atan2(x1, d)); printf("atan2(NAN, -1.0) = %+.15f\n", atan2(d, -x1)); /* * atan2(pi/2, 1.0) = 1.003884821853887 * atan2(2.0, -3*pi/4) = 2.437780340738381 * atan2(-4.0, 4.0) = -0.785398163397448 * atan2(3.0, -3.0) = 2.356194490192345 * atan2(+0.0, +0.0) = +1.570796326794897 * atan2(+0.0, -0.0) = +1.570796326794897 * atan2(-0.0, +0.0) = +1.570796326794897 * atan2(-0.0, -0.0) = +1.570796326794897 * atan2(+0.0, -4.0) = +3.141592653589793 * atan2(-0.0, +3.0) = +0.000000000000000 * atan2(-4.0, +0.0) = -1.570796326794897 * atan2(+3.0, -0.0) = +1.570796326794897 * atan2(INFINITY, 1.0) = +1.570796326794897 * atan2(INFINITY, -1.0) = -1.570796326794897 * atan2(1.0, -INFINITY) = +3.141592653589793 * atan2(-3.0, -INFINITY) = -3.141592653589793 * atan2(1.0, INFINITY) = +0.000000000000000 * atan2(-3.0, INFINITY) = -0.000000000000000 * atan2(1.0, NAN) = +nan * atan2(NAN, -1.0) = +nan * * */
Fortran interface:
REAL(8) :: X = 3.0 REAL(8) :: Y = -3.0 PRINT*, ATAN2(Y, X) ! ! OUTPUT ! 2.356194490192345 !
父主题: 三角函数