[Python-ideas] Float range class

Todd toddrjen at gmail.com
Thu Jan 8 18:12:32 CET 2015


On Thu, Jan 8, 2015 at 5:18 PM, M.-A. Lemburg <mal at egenix.com> wrote:

> On 08.01.2015 17:01, Todd wrote:
> > Currently, the range class is limited to integers.  However, in many
> > applications, especially science and mathematics, ranges of float values
> > are the norm.
> >
> > The current approaches for float ranges all have significant limitations.
> > numpy.arange pre-allocates the values and doesn't use python floats, both
> > of which affect performance.  List comprehensions also have to be
> > pre-allocated.  Generators and values created in the body of a loop
> cannot
> > be indexed or re-used and are much more verbose and harder to read.  So
> it
> > would be nice to have a float equivalent of the existing range class.
> >
> > Assuming such a class is worthwhile, I see three possible ways to handle
> > float ranges, each with its own strengths and weaknesses.  I am not sure
> > which, if any, is preferable.
> >
> > The first is to extend the existing range class so it can support floats
> or
> > to use duck-typing to support any class that has the necessary methods.
> > However, I would be worried about making such a fundamental change to
> such
> > a core class, and either approach could hurt performance.
> >
> > The second approach is to create a new class that handles floating-point
> > ranges (perhaps called "frange") and/or a new class that handles
> duck-typed
> > ranges (perhaps called "drange").  However, there isn't really a good
> place
> > right now to put these as far as I can see.
> >
> > The third approach is to create a new module for various range classes.
> > For example there could be a float range, a datetime range, a decimal
> > range, a duck-typed range, an abstract base class for making new range
> > classes, etc.  However, this is a lot more work (although it wouldn't
> need
> > to all be done at one time).
>
> I think you'd first have to describe some use cases, since it's
> not at all clear what you mean with "float range", e.g. you
> could be referring to:
>
> * interval arithmetics: http://en.wikipedia.org/wiki/Interval_arithmetic
>
> * ranges of numbers with a fixed stepping (which can create problems
>   near the edges due to rounding issues)
>

This is what I am talking about.  The idea would be to have something that
is, as much as possible, identical to the existing range.  I understand it
has floating-point issues, but any other approach would as well.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150108/0456dd29/attachment.html>


More information about the Python-ideas mailing list