约 1234 字

约 6 分钟

#C 语言标准库函数 remainderf

#include <math.h>

float remainderf(float x, float y);

说明

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

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

自 C99 起提供。

参数

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

返回值

  • 计算得到的余数。

#示例

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

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

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

运行结果。

-0.5

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28