Elementary confusion

Sean 'Shaleh' Perry shalehperry at attbi.com
Mon Sep 23 19:55:00 EDT 2002


On Monday 23 September 2002 16:36, John Baxter wrote:
> >>> a=0.1
> >>> b=0.2
> >>> c=a+b
> >>> c==0.3
>
> 0
>
> >>> c
>
> 0.30000000000000004
>
> >>> d=0.3
> >>> d
>
> 0.29999999999999999
>
>
> We "know" that c is 0.3.  The computer has added two inexact values
> which are "too big" and produced a result which is therefore both "too
> big" and not the nearest representation of 0.3, which is "too small".
>
>   --John

Every C programming book I have ever read makes the comment that == and 
floating point do not mix.  Just one the things you learn and accept.




More information about the Python-list mailing list