#C 语言标准库函数 remainder
#include <math.h>
double remainder(double x, double y);
说明
求浮点余数。中间商取最接近精确商的整数,恰好在中间时取偶数。该选择独立于当前舍入方向。
除数为零可能报告定义域错误。在 IEC 60559 实现中,零结果保留被除数的符号。
自 C99 起提供。
参数
x- 被除数。y- 除数。
返回值
- 计算得到的余数。
#示例
使用 GCC 时,在链接命令末尾添加 -lm。
#include <math.h>
#include <stdio.h>
int main(void)
{
double computed = remainder(7.5, 2.0);
printf("%Lg\n", (long double)computed);
return !(computed == -0.5);
}
运行结果。
-0.5
#相关接口
- 接口变体 remainderf、remainderl、remainderd32、remainderd64、remainderd128
- 类型通用分派 remainder(类型通用宏)
- 相关操作 fmod、remquo