约 1459 字

约 7 分钟

#C 语言标准库函数 getpayloadd32

#define __STDC_WANT_IEC_60559_EXT__ 1
#include <math.h>

_Decimal32 getpayloadd32(const _Decimal32 *src);

说明

获得浮点对象的 NaN 载荷,以相同浮点类型表示其非负整数值。

载荷范围取决于浮点格式,业务代码可按目标实现的约定解释载荷。

自 C23 起提供。需要实现支持相应的 IEC 60559 浮点扩展,并在包含头文件前定义 __STDC_WANT_IEC_60559_EXT__。十进制版本还需要实现定义 __STDC_IEC_60559_DFP__。

参数

  • src - 指向浮点对象的只读指针。

返回值

  • 输入为 NaN 时返回载荷,否则返回 -1。

#示例

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

#define __STDC_WANT_IEC_60559_EXT__ 1
#include <math.h>
#include <stdio.h>

int main(void)
{
    _Decimal32 value = 2.0df;
    _Decimal32 computed = getpayloadd32(&value);
    printf("%Lg\n", (long double)computed);
    return !(computed == -1.0df);
}

运行结果。

-1

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28