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

Discussion in 'C Programming' started by John Reye, Jul 7, 2012.

1. ### John ReyeGuest

Hi,

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

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.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.

John Reye, Jul 7, 2012