基于 X3.9-1978 标准的最佳 IEEE 754-1985 表示

Best IEEE 754-1985 representation for X3.9-1978 based standard

根据 DICOM 标准,可以使用十进制字符串的值表示来存储一种浮点数。见 Table 6.2-1. DICOM Value Representations:

Decimal String: A string of characters representing either a fixed point number or a floating point number. A fixed point number shall contain only the characters 0-9 with an optional leading "+" or "-" and an optional "." to mark the decimal point. A floating point number shall be conveyed as defined in ANSI X3.9, with an "E" or "e" to indicate the start of the exponent. Decimal Strings may be padded with leading or trailing spaces. Embedded spaces are not allowed.

"0"-"9", "+", "-", "E", "e", "." and the SPACE character of Default Character Repertoire. 16 bytes maximum

因此,基于输入最多存储在16 个字节。

X3.9-1978 了解更多的人能否确认这是最好的表示形式(与 arbitrary-precisionfloat and/or [=15= 相比])?最好的情况是,表示是往返的 read/write 将 视觉无损 。我应该能够从磁盘读取这样的 ASCII 浮点表示,将其放入内存,然后将其写回磁盘(如上所述),与原始值(尽可能 = 机器 epsilon)相比具有最大精度。关于如何将 double 表示为仅 16 字节存储的 ASCII 的实际实现细节不在本问题的讨论范围内,有关详细信息,请参阅 ..

这主要基于 Hans Passant 和 Mark Dickinson 的评论。

使用任何浮点类型来表示十进制值通常不是一个好主意,因为二进制浮点类型不能完全表示十进制值。通常从不使用它们来处理确切的货币价值。

但在这里,DICOM 规范将限制设置为 16 个字符,而双精度精度约为 15-16 位十进制数字 (ref.)。一旦您的十进制字符串包含一个符号 (+/-)、一个点 (.) 或一个指数部分 (e/E),您将最多有 15 个十进制数字,并且往返应该是正确的。当您有 16 位数字时,应该会出现唯一的问题。 Mark Dickinson 提供的示例是:16 个字符的字符串 99999999999999979999999999999996 都将映射到相同的 IEEE 754 二进制 64 浮点值。

TL/DR:Hans Passant 给出了一个很好的摘要:“最多 16 个字节”[是] 与您可以存储在双精度数中的准确有效数字一样多。此 DICOM 规范旨在让您使用 double。所以就用它


免责声明:IEEE 754 可接受的所有值都将得到正确处理,但请注意,1e1024 将是 DICOM 十进制字符串的可接受值,但它不能以双精度表示(限制在大约 1e308 ).