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