[Python-ideas] Float range class

Chris Barker chris.barker at noaa.gov
Thu Jan 8 17:42:06 CET 2015


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

> I think you'd first have to describe some use cases,
>
 <snip>

> * ranges of numbers with a fixed stepping (which can create problems
>   near the edges due to rounding issues)
>
<snip>

> Looping over such ranges doesn't sound like a useful operation,
>

Good point -- it is very common to want such a range of number in a
sequence -- but does it need to be an iterator? Though in keeping with
python's move to iterators by default, why not?


> except for the case where you have a fixed stepping (and those
> can easily be implemented by mapping an integer to a stepping
> in your interval).
>

and range can be easily implemented with a while loop.

Such fixed stepping sequences are really common, so convenience functions
make sense. But more to the point, as you mention above (and I mentioned in
a previous email), there can be problems near the edges due to rounding
issues, so it would be nice to provide a built-in that addresses those
problems consistently and predictably, rather than having each user write
their own naive implementation and get it wrong much of the time.

NOTE: for many of us those common use-cases also involve doing a bunch of
computation of arrays of numbers, and thus involve numpy anyway.

-Chris


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150108/3709c00f/attachment.html>


More information about the Python-ideas mailing list