[Python-Dev] range objects in 3.x (original) (raw)

Guido van Rossum guido at python.org
Tue Sep 27 22:13:41 CEST 2011


On Tue, Sep 27, 2011 at 1:05 PM, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:

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.

But why offer an API that is an attractive nuisance? I don't think that it is a burden to the user to have to specify "from 0 to 2 inches in 8 steps" instead of "from 0 to 2 inches in 1/4 inch steps". (And what if they tried to say "from 0 to 3 1/4 inches in 1/2 inch steps" ?)

-- --Guido van Rossum (python.org/~guido)



More information about the Python-Dev mailing list