PEP 260: simplify xrange()

James Logajan JamesL at Lugoj.Com
Wed Jun 27 14:30:17 EDT 2001


Jeff Shannon wrote:
> To make a long story short, the discussion regarding FP boils down to the
> fact that "1.0" cannot be exactly represented in FP.  Every time you increment
> your "frange", you are introducing nasty rounding errors, and by the time
> you've
> done several thousand iterations, they're going to be very significant
> rounding
> errors.

Perhaps you mean 0.1 can't be represented exactly using standard internal
representations? Because 1.0 can and is represented exactly (unless the
string to float algorithm is seriously brain-dead). See:

>>> a = 1.0
>>> b = a + a + a
>>> if b == 3.0:
...     print "aha!"
... 
aha!

As long as the integers don't get too large and you aren't dealing with
division that results in fractions does the issue get muddled. But if you
are stepping by 0.1, yes you will have some issues when trying to do exact
comparisons.



More information about the Python-list mailing list