7 digit decimal number

Jerome Coonen jeromeabe.com
Sun Apr 11 13:10:40 PDT 1999


Following Fred Tydeman's request for a 7-digit decimal that
wouldn't make the round trip to IEEE single and back, Lyle
Ramshaw responded:

>Fred, you were almost there!  The number 1e28 is such an example.
>Converting 10^28 to floating-point binary, we get
>
> 1.00000010011111100111001011110001111100010010100000010011000010001 x 2^93,
>                         ^
>...

The fascination with six and seven digit numbers has arisen with regard
to the proposed new C standard.  The claim is that to distinguish
P-digit decimals by p-bit binary numbers, it suffices to satisfy

  10^P < 2^(p-1)

When p=24 for IEEE arithmetic  2^23 = 8,388,608  so P=6.

Fred noticed that P is "nearly" 7, in the sense that over various
limited ranges, 24-bit floating point numbers would suffice to
distinguish 7-digit values.  That is, the inequality above is a
*sufficient* not necessary condition for separation.  The range
of IEEE values, however, is sufficiently wide that the inequality
is a necessary condition as well.

Mr. Ramshaw pointed out one faulty 7-digit value. Here's a way to
hunt for more.  Look for  2^n  barely<  10^N  (no, barely< is not
a new C9X operator).  A nice case is

  2^93  =  9.903520314...E28

In the interval  [2^93, 10^28]  the spacing of 24-bit binary
values is  2^(93-23) = 1.18E21.  The spacing of 6-digit decimals
is  10^(27-5) = 1.E22, but the spacing of 7-digit decimals is
1.E21, just less than the binary spacing.

A simple population count illustrates there are too many 7-digit
values to be distinguished by 24-bit values.

Because  2^93 = 9.903520E27  to seven digits, there are

  10,000,000 - 9,903,520  =  96480

decimals up to 10^28.  On the other hand,

  10^28  =  0x813F39 * 2^70

so there are  0x13F39 = 81721  24-bit values in the interval.
There are some fifteen thousand too many decimal values --
values that can't make the round trip.

-Jerome Coonen



More information about the Numeric-interest mailing list