小编Gav*_*and的帖子

正确的 strtod 实现?

简单的问题:双精度数字 1.15507e-173 的正确位表示是什么?完整问题:如何确定这个数字的正确解析?

背景:我的问题来自这个答案,它显示了来自三个不同解析器的两种不同的位表示,即

0x1c06dace8bda0ee0
Run Code Online (Sandbox Code Playgroud)

0x1c06dace8bda0edf
Run Code Online (Sandbox Code Playgroud)

我想知道哪个解析器做对了。

C99 规范的更新第 6.4.4.2 节说对于 C 解析器,

"...the result is either the nearest representable value, or the larger
or smaller representable value immediately adjacent to the nearest
representable value, chosen in an implementation-defined manner."
Run Code Online (Sandbox Code Playgroud)

这意味着解析的数字不需要是最近的,甚至不需要是两个相邻的可表示数字之一。7.20.1.3 中的相同规范表示 strtod() 的行为方式与内置解析器基本相同。感谢指出这一点的回答者。

另请参阅对类似问题的回答此博客

c floating-point strtod

5
推荐指数
1
解决办法
1295
查看次数

标签 统计

c ×1

floating-point ×1

strtod ×1