PEP 260: simplify xrange()

Jeff Shannon jeff at ccvcorp.com
Thu Jun 28 12:35:25 EDT 2001


James Logajan wrote:

> 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?

Whoops!  Yes, that's exactly what I meant.

Gotta start proofreading better before I hit "send" ...  :)

>>> count = 0.0
>>> for i in range(10):
...  count += 0.1
...  repr(count)
...
'0.10000000000000001'
'0.20000000000000001'
'0.30000000000000004'
'0.40000000000000002'
'0.5'
'0.59999999999999998'
'0.69999999999999996'
'0.79999999999999993'
'0.89999999999999991'
'0.99999999999999989'

Many things can get thrown off by those little rounding errors.  (Or, if
you don't like "errors", then... unpredicted differences.  <wink>  )

Mind you, all of this could potentially be solved by the
rational numbers/decimal FP proposals that have been
brought up in the not-too-distant past...

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list