[Python-ideas] Float range class

Devin Jeanpierre jeanpierreda at gmail.com
Fri Jan 9 04:20:39 CET 2015


On Thu, Jan 8, 2015 at 7:13 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, Jan 08, 2015 at 05:01:03PM +0100, 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.
> [...]
>
> Solving this problem for the standard library would be a good idea. The
> math module might be the best place for it, although that would require
> giving up the concept that it is a thin wrapper around your platform's C
> math routines. (I'm not sure just how much that idea still applies.)
>
-snip-
> If something like this makes it into the standard library, I think it is
> important that it isn't limited to just floats. If you pass it
> Fractions, or Decimals, it should return Fractions or Decimals, and not
> just convert everything to float.
-snip-
> As for where it should live, the math module is the obvious place, but
> it is written in C (which is a barrier to adding new functionality, as
> opposed to Python modules).

I actually expect the math module to convert to float, just like I
expect the cmath module to convert to complex. For example:

# python 3.4
>>> math.sqrt(decimal.Decimal(0))
0.0

Are there any exceptions to this?

-- Devin


More information about the Python-ideas mailing list