约 1221 字

约 6 分钟

#C 语言标准库函数 samequantumd64

#include <math.h>

bool samequantumd64(_Decimal64 x, _Decimal64 y);

说明

比较两个十进制浮点值的量子指数,可区分数值相等而末尾零不同的表示。

量子指数比较独立于两个数的大小。

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

参数

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

返回值

  • 有相同量子指数时返回 true,否则返回 false。两者同为 NaN 或同为无穷时也返回 true。

#示例

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

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

int main(void)
{
    bool computed = samequantumd64(1.20dd, 2.50dd);
    printf("%d\n", (int)computed);
    return !(computed == 1);
}

运行结果。

1

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28