约 1311 字

约 7 分钟

#C 语言标准库函数 fmaxd32

#include <math.h>

_Decimal32 fmaxd32(_Decimal32 x, _Decimal32 y);

说明

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

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

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

参数

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

返回值

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

#示例

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

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

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

运行结果。

3

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28