As per DICOM standard, a type of floating point can be stored using a Value Representation of Decimal String. See 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
So I would be tempted to simply use 64 bits double
(IEEE 754-1985
) to represent the value in memory in my C code, based on the fact that input is stored on a maximum of 16 bytes.
Could someone with a little bif more knowledge of X3.9-1978
confirms that this is the best possible representation (compared to arbitrary-precision
, float
and/or long double
) ? By best, I mean the representation were round-trip read/write will be visually lossless. I should be able to read such ASCII floating point representation from disk, put it into memory, and write it back to disk (as specified above) with maximum accuracy compared to the original values (= machine epsilon when possible). The actual implementation details on how to represent a double
as ASCII with only 16 bytes of storage is outside the scope of this question, see here for details..