约 1227 字

约 6 分钟

#C 语言标准库函数 fmaxf

#include <math.h>

float fmaxf(float x, float y);

说明

比较两个实浮点数,选择较大值。只有一个参数为 NaN 时选择另一个参数。

对大小相等的两个带符号零,基本接口不保证固定的符号。

自 C99 起提供。

参数

  • x - 参与运算的实浮点值。
  • y - 第二个实浮点操作数。

返回值

  • 选择的较大值。两个参数均为 NaN 时返回 NaN。

#示例

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

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

int main(void)
{
    float computed = fmaxf(-7.0f, 3.0f);
    printf("%Lg\n", (long double)computed);
    return !(computed == 3.0);
}

运行结果。

3

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28