#C 语言标准库宏 lround
下面以函数形式说明宏的调用接口。
#include <tgmath.h>
long int lround(generic_value x);
说明
将实数就近舍入且中点远离零取整。 示例的实参类型选择 lroundf。
舍入规则独立于当前浮点舍入方向。结果无法表示(包括无穷或 NaN)时可能报告定义域或范围错误,返回值不能当作有效整数使用。
适用的二进制实浮点类型和整数参与分派。含 long double 时选长双精度版本,否则含 double 或整数时选双精度版本,其余选择 float 版本。 实现支持十进制重载时,不能把其参与分派的十进制实参和二进制浮点或复数实参混用。
自 C99 起提供。
参数
x- 参与运算的实浮点值。
返回值
- 返回舍入后的整数值。返回类型为
long int。
#示例
使用 GCC 时,在链接命令末尾添加 -lm。
#include <tgmath.h>
#include <stdio.h>
int main(void)
{
long int computed = lround(-2.5f);
printf("%ld\n", computed);
return !(computed == -3);
}
运行结果。
-3
#相关接口
- 类型通用分派 lround、lroundl、lroundd32、lroundd64、lroundd128
- 相关操作 llround(类型通用宏)、round(类型通用宏)