A double floating point number has 53 mantissa bits (
DBL_MANT_DIG
) where the MSB is implicit set and 52 bits are stored. The corresponding number of decimal digits is
log10(2^53) = 53 * log10(2) = 15.95
Rounding that value down is used as
DBL_DIG
. So there is nearly one more decimal digit of precision.
DBL_DECIMAL_DIG
specifies the number of decimal digits that can be rounded to a double precision number and back again without change to the value. It must be one more than the uprounded precision of 16 to satisfy this requirement. See also the standard at
<float.h>[
^].
So printing a value with 17 significant decimal digits and converting that back to double precision will result in the same value. When printing only 16 digits, the converted value might be not identical.
Microsoft has no native support for
long double
precision:
The representation of long double and double is identical. However, long double and double are separate types.
Therefore the
LDBL_xxx
definitions are using the corresponding
DBL_xxx
definitions.