[Tutor] is this a bug?
Remco Gerlich
scarblac@pino.selwerd.nl
Wed, 2 Jan 2002 18:25:07 +0100
On 0, Michael Goodfellow <mgoodfellow@usa.net> wrote:
> While just working through some list syntax eaxamples, I typed this:
>
> >>> 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?
The problem is that, when converted to binary, 66.6 is repeating. There is
no way to represent it exactly in a finite amount of binary digits.
This is not a Python problem but a symptom of the way computers do floating
point math (some other languages may not *show* this, but they have it too).
The str() of a number has an abbreviated form, the repr() shows the Truth.
Compare
>>> str(66.6)
66.6
>>> repr(66.6)
66.599999999999994
--
Remco Gerlich