#C 语言标准库宏 atan2pi
下面以函数形式说明宏的调用接口。
#include <tgmath.h>
generic_result atan2pi(generic_value y, generic_value x);
说明
按两个直角坐标求方向角,并将结果表示为 π 的倍数。 示例的实参类型选择 atan2pif。
参数次序为竖直坐标在前。符号参与象限选择。
适用的二进制实浮点类型和整数参与分派。含 long double 时选长双精度版本,否则含 double 或整数时选双精度版本,其余选择 float 版本。 实现支持十进制重载时,不能把其参与分派的十进制实参和二进制浮点或复数实参混用。
自 C23 起提供。
参数
y- 竖直坐标。x- 水平坐标。
返回值
- 返回 [-1, 1] 中的方向角,示例为 0.75。
#示例
使用 GCC 时,在链接命令末尾添加 -lm。
#include <tgmath.h>
#include <stdio.h>
int main(void)
{
float computed = atan2pi(1.0f, -1.0f);
printf("%Lg\n", (long double)computed);
return !(computed == 0.75);
}
运行结果。
0.75
#相关接口
- 类型通用分派 atan2pi、atan2pil、atan2pid32、atan2pid64、atan2pid128
- 相关操作 atan(类型通用宏)、atan2(类型通用宏)、atanpi(类型通用宏)