Generating equally-spaced floats with least rounding error

Arnaud Delobelle arnodel at gmail.com
Sat Sep 24 16:18:44 CEST 2011


On Sep 24, 2011 2:59 PM, "Chris Angelico" <rosuav at gmail.com> wrote:
>
> On Sat, Sep 24, 2011 at 11:53 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
> > #1 add multiples of the width to the starting value, 0.
> >
> > #2 subtract multiples of width from the ending value, 2.1.
>
> #3, go half and half - generate the lower half by adding to the lower
> bound, and the upper half by subtracting from the upper bound. Not

#4 the barycentric approach.

    ((n-i)*a + i*b)/n for i in range(n+1)

Gives you n+1 equally spaced values between a and b inclusive

Arnaud
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110924/6abac2fb/attachment.html>


More information about the Python-list mailing list