约 1351 字

约 7 分钟

#C 语言标准库函数 totalordermagf

#define __STDC_WANT_IEC_60559_EXT__ 1
#include <math.h>

int totalordermagf(const float *a, const float *b);

说明

按 IEC 60559 幅度全序比较两个浮点对象。排序规则覆盖带符号零、无穷与 NaN。

全序比较可用于排序,遇到 NaN 时也有确定的排序规则。

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

参数

  • a - 指向第一个浮点操作数的指针。
  • b - 指向第二个浮点操作数的指针。

返回值

  • 若第一个值排在第二个值之前或与它等价,返回非零,否则返回零。

#示例

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

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

int main(void)
{
    float first = 1.0f;
    float second = 2.0f;
    int computed = totalordermagf(&first, &second);
    printf("%d\n", computed);
    return !(computed != 0);
}

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28