约 1160 字

约 6 分钟

#C 语言标准库函数 strtod64

#include <stdlib.h>

_Decimal64 strtod64(const char *restrict nptr, char **restrict endptr);

说明

跳过当前 locale 定义的前导空白,解析有效的浮点数前缀。

无可转换内容时,若 endptr 非空,保存的地址等于原输入。小数点取当前 LC_NUMERIC 的设置。格式允许指数和实现支持的无穷及 NaN 写法。

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

参数

  • nptr - 以空字符结束的输入字符串。
  • endptr - 接收首个未转换字符的地址,可传空指针。

返回值

  • 返回解析的数值,无法转换时返回零。上溢时设置 ERANGE 并返回相应类型的有符号大值。下溢的返回按标准与实现规则处理。

#示例

#include <stdlib.h>
#include <errno.h>

int main(void)
{
    const char text[] = "42!";
    char *end;
    errno = 0;
    _Decimal64 value = strtod64(text, &end);
    return errno == ERANGE || end == text || *end != '!' || value != 42;
}

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28