约 1149 字

约 6 分钟

#C 语言标准库函数 fmodf

#include <math.h>

float fmodf(float x, float y);

说明

计算浮点除法的余数,商按向零舍入取整数。

除数为零或被除数为无穷时,可能报告定义域错误。

自 C99 起提供。

参数

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

返回值

  • 余数,正常结果的绝对值小于除数的绝对值,符号与被除数一致。

#示例

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

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

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

运行结果。

-1.5

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28