IEEE 754 规范中的十进制转换范围(二进制浮点运算)

发布于 2024-09-14 23:20:10 字数 307 浏览 16 评论 0原文

Table 2 in section 5.6 on the bottom of page 11 of the IEEE 754 specification lists the ranges of decimal values for which decimal to binary floating-point conversion must be performed. The ranges of exponents don't make sense to me. For example, for double-precision, the table says the maximum decimal value eligible to be converted is (1017-1)*10999. That's way bigger then DBL_MAX, which is approximately 1.8*10308. Obviously I'm missing something -- can someone explain this table to me? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏至、离别 2024-09-21 23:20:10

[旁注:从技术上讲,您链接到的文档不再是标准; “IEEE 754”实际上应该仅用于指代 2008 年发布的标准的更新版本。]

我的理解是,正如您所说,该表的左侧列描述了任何十进制字符串的有效输入范围到提供的二进制浮点转换。例如,类似于 '1.234e+879' 的十进制字符串表示值 1234*10^876 (M = 1234,N = 876),因此在表限制内,并且是需要被转换功能接受。但请注意,十进制字符串到底可以采用什么形式超出了 IEEE 754 的范围;这只是这里相关的值。

我不认为某些允许的输入超出双精度数的可表示范围是一个问题;在这种情况下,应遵循通常的溢出规则;参见文档第 7.3 节。也就是说,应该发出溢出异常信号,并假设它没有被捕获,如果舍入模式是舍入到最接近的值或舍入到正无穷大,则转换结果(例如,对于超出范围的正值)为正无穷大,以及最大的有限可表示值(如果舍入模式向负无穷大舍入或向零舍入)。

更微妙的是,根据我对本文档的阅读,转换函数也应该接受像 '1e+1000' 这样的十进制字符串,因为它表示的值可以用 10 * 10^999 的形式表示,甚至可以用 10000000000000000 * 10 的形式表示^984。请参阅第 5.6 节中以“输入时,应将尾随零附加到 M ...”开头的句子。

从公开的草案版本来看,当前版本的 IEEE 754 在这方面似乎有点不同 (版本 1.2.5):它只需要每个实现在十进制字符串的指数上指定界限 [-η, η],其中 η 足够大以容纳小数对应于最大支持的二进制格式的有限二进制值的字符串;因此,如果 bin64 格式是最大支持的格式,那么在我看来,例如 η = 400 就足够大了。

[Side note: technically, the document you link to is no longer a standard; "IEEE 754" should really only be used to refer to the updated edition of the standard published in 2008.]

My understanding is that, as you say, the left-hand column of that table describes the range of valid inputs to any decimal string to binary float conversion that's provided. So for example, a decimal string that's something like '1.234e+879' represents the value 1234*10^876 (M = 1234, N = 876), so is within the table limits, and is required to be accepted by the conversion functionality. Though note that exactly what form the decimal strings are allowed to take is outside the scope of IEEE 754; it's only the value that's relevant here.

I don't think it's a problem that some of the allowed inputs can be outside the representable range of a double; the usual rules for overflow should be followed in this case; see section 7.3 of the document. That is, the overflow exception should be signaled, and assuming that it's not trapped the result of the conversion (for a positive out-of-range value, say) is positive infinity if the rounding mode is round to nearest or round towards positive infinity, and the largest finite representable value if the rounding mode is round towards negative infinity or round towards zero.

Slightly more subtly, from my reading of this document, a decimal string like '1e+1000' should also be accepted by the conversion function, since the value it represents is expressible in the form 10 * 10^999, or even 10000000000000000 * 10^984. See the sentence that starts 'On input, trailing zeros shall be appended to or stripped from M ...' in section 5.6.

The current version of IEEE 754 seems to be a bit different in this respect, judging by the publicly available draft version (version 1.2.5): it just requires each implementation to specify bounds [-η, η] on the exponent of the decimal string, with η large enough to accomodate the decimal strings corresponding to finite binary values in the largest supported binary format; so if the binary64 format is the largest supported format, it looks to me as though η = 400 would be plenty big enough, for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文