123.3 + 0.1 is 123.3999999999 ?

Grant Edwards grante at visi.com
Fri May 16 09:13:24 EDT 2003


In article <mailman.1053072988.5541.python-list at python.org>, Simon Brunning wrote:

> Ah, but try this:
> 
>>>> sum = 0.0
>>>> for i in range(10): sum += 0.1
> ... 
>>>> sum == 1
> 0
> 
> So, if you do any equality tests, even tiny inaccuracies can
> trip you up. Using FixedPoint:
> 
>>>> import FixedPoint as fp
>>>> sum = fp.FixedPoint(0.0)
>>>> for i in range(10): sum += sum += 0.1
> ... 
>>>> sum == 1
> 1
> 
> This works as expected.

So did the first example.  ;)

-- 
Grant Edwards                   grante             Yow!  Yes, but will I
                                  at               see the EASTER BUNNY in
                               visi.com            skintight leather at an
                                                   IRON MAIDEN concert?




More information about the Python-list mailing list