Count Down to Zero

Tim Peters tim_one at email.msn.com
Fri Sep 22 17:38:10 EDT 2000


> How come Python can't count down to zero?

If you try it, you'll discover the same thing happens in Perl, Java, C, C++,
Fortran ... and every other language that lets you use the floating-point
hardware you paid for.

> Was it written by ancient Romans or something?

Modern Dutch, actually.  But, I agree, pretty much the same thing to
Americans <wink>.

Using pencil and paper, try repeatedly subtracting 0.3333 from 1.0000.  Do
you reach exactly 0 then?  Same thing, except decimal instead of binary.
0.1 isn't exactly representable in binary floating-point, just as 1/3 isn't
in decimal floaing-point.

I recently posted a link to my old FixedPoint.py module (read "DejaNews").
Grab that if you want the illusion of exact decimal arithmetic.

you'll-sure-pay-for-it-in-runtime-though-ly y'rs  - tim





More information about the Python-list mailing list