[Tutor] is this a bug?

Gregor Lingl glingl@aon.at
Wed, 2 Jan 2002 18:41:33 +0100


> >>>> a = [66.6, 333, 333, 1, 1234.5]
> >>>> a # then hit enter key
> >
> ># It returned this:
> >
> > [66.599999999999994, 333, 333, 1, 1234.5]
> >
> > Any comments?
> >
>
> .6 is not a perfect decimal.  Which is why you get the number above.
Think
> about it -- 2/3 is a repeating decimal.
>

Perfect in the sense you *need* are only (negative) powers of 2
(and integer multiples of them):

>>> 0.5
0.5
>>> 0.25
0.25
>>> 0.125
0.125
>>> 0.0625
0.0625
>>> 0.0625 / 2
0.03125
>>> 0.03125 / 2
0.015625
>>> _ / 2
0.0078125
>>> _ / 2
0.00390625
>>> 0.03125 * 7
0.21875

but:

>>> 0.0624
0.062399999999999997
>>> 0.0624 * 7
0.43679999999999997
>>>

ond so on ...

I think this depends not on the
decimal beeing repeating like 2/3
or not (like 0.6 = 3/5).

Gregor

Gregor