This math scares me

Fabio Olive Leite olive at conectiva.com.br
Thu Mar 15 08:53:56 EST 2001


Hi there,

On Wed, Mar 14, 2001 at 09:31:54PM +0000, Grant Edwards wrote:
) No.  The binary floating point representation of many decimal
) fraction values is not exact.  That's what started this whole
) thread.  You can't represent 0.1 exactly in binary FP.  You can
) in BCD.

Just to make matters worse in this discussion, let me add some more noise.

Since base 10 contains base 2 and base 5 (`factor 10`), every number coming
from any of those bases is exactly represented in base 10. Conversely, base
2 contains only itself, and thus it cannot represent correctly some numbers
that are exactly representable in other bases, like 0.1 in base 10.

The usual 1/3 example is a problem for base 10, but not so for base 12, for
example, since 12 contains 3 2 2. Thus:

1_{12} / 3_{12} == 0.4_{12}

And then base 30 would let us count exactly fractions of base 2, 3, 5, 6,
10, 12, 15, 16 and all the others you can think of that have only 2, 3 and
5 as factors of the base. But since no one (usualy) has 30 fingers, that
base is not terribly popular. :)

Please shoot me if this is just a bad dream.

Fábio
-- 
( Fábio Olivé Leite -*- http://www.conectiva.com.br/~olive )




More information about the Python-list mailing list