Velocity Reviews > Derivation of the C Standard's Formula for FLT_DIG, DBL_DIG, LDBL_DIG

# Derivation of the C Standard's Formula for FLT_DIG, DBL_DIG, LDBL_DIG

John Reye
Guest
Posts: n/a

 07-07-2012
Hi,

have you seen the C Standards formula for FLT_DIG, DBL_DIG, LDBL_DIG?

http://www.open-std.org/jtc1/sc22/wg...70.pdf#page=49 (pdf-
page 49)

If you have a capable browser, it can be displayed like this:

⎧ p log10 b if b is a power of 10
q = ⎨
⎩ ⎣( p − 1) log10 b⎦ otherwise

How does one derive this formula? (And: is it correct, in the sense of
really defining the maximum for q ?)

I'm particularly interested in the "otherwise" case, which states q <=
floor((p-1)*log10(b))

In particular: cannot q be somewhat larger, as in q <=
floor(p*log10(b)) = LIM ??? I believe that also results in no rounding
loss; and an exact representation (of the original decimal number)

(((In fact... q might even be able to be larger still (than LIM), for
cases where there is a non-exact representation of the original number
with p radix-b digits; but rounding back to base-10, would still yield
the original number.)))

Thanks.
J.