[Python-Dev] range objects in 3.x
Alexander Belopolsky
alexander.belopolsky at gmail.com
Tue Sep 27 22:05:01 CEST 2011
On Tue, Sep 27, 2011 at 2:53 PM, Guido van Rossum <guido at python.org> wrote:
> On Tue, Sep 27, 2011 at 11:48 AM, Alexander Belopolsky
> <alexander.belopolsky at gmail.com> wrote:
>> On Tue, Sep 27, 2011 at 2:36 PM, Guido van Rossum <guido at python.org> wrote:
>> ..
>>> But that's exactly what we don't *want* you to do! Because (unless you
>>> are a numerical wizard) you probably aren't doing the error analysis
>>> needed to avoid the "unexpected extra point" problem due to floating
>>> point inaccuracies. For your own good, we want you to state the count
>>> and let us deliver the number of points you want.
I don't disagree that the ability to provide count= option is useful.
I am just saying that there are also cases where float step is known
exactly and count (or stop) can be deduced from stop (or count)
without any floating point issues. Iteration over integers that
happen to be represented by floats is one use case, but using integer
range may be a better option in this case. In US it is still popular
to measure things in power of two fractions. Simulating a carpenter's
yard does not suffer from rounding when done in floats. Counting by
.5 and .25 has its uses too. Maybe frange() should just signal the FP
inexact exception if we expect users to need hand holding to such a
degree.
More information about the Python-Dev
mailing list