约 1255 字

约 6 分钟

#C 语言标准库函数 remainderd64

#include <math.h>

_Decimal64 remainderd64(_Decimal64 x, _Decimal64 y);

说明

求浮点余数。中间商取最接近精确商的整数,恰好在中间时取偶数。该选择独立于当前舍入方向。

除数为零可能报告定义域错误。在 IEC 60559 实现中,零结果保留被除数的符号。

自 C23 起提供。需要实现定义 __STDC_IEC_60559_DFP__ 并提供对应的十进制浮点接口。

参数

  • x - 被除数。
  • y - 除数。

返回值

  • 计算得到的余数。

#示例

使用 GCC 时,在链接命令末尾添加 -lm。

#include <math.h>
#include <stdio.h>

int main(void)
{
    _Decimal64 computed = remainderd64(7.5dd, 2.0dd);
    printf("%Lg\n", (long double)computed);
    return !(computed == -0.5dd);
}

运行结果。

-0.5

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28