[Python-ideas] PEP 485: A Function for testing approximate equality

Chris Angelico rosuav at gmail.com
Fri Feb 6 01:40:57 CET 2015


On Fri, Feb 6, 2015 at 11:24 AM, Chris Barker <chris.barker at noaa.gov> wrote:
> If we really believe that almost all people will be working with numbers of
> around a magnitude of 1, then we could set a default -- by why in the world
> are you using floating point numbers with a range of about 1e-300 to 1e300
> in that case?

Because 'float' is the one obvious way to handle non-integral numbers
in Python. If you simply put "x = 1.1" in your code, you get a float,
not a decimal.Decimal, not a fractions.Fraction, and not a complex. We
don't need separate data types for "numbers around 1" and "numbers
around 1e100"... not for the built-in float type, anyway. To the
greatest extent possible, stuff should "just work".

Unfortunately the abstraction will always leak, especially when you
work with numbers > 2**53 or < 2**-53, but certainly there's nothing
wrong with using a data type that gives you *more* range. In theory, a
future version of Python should be able to switch to IEEE 754 Quad
Precision and push the boundaries out, without breaking anyone's code.
Then people will be using a data type with a range of something like
1e-5000 to 1e5000... to store values close to 1. Ain't computing
awesome! (Obligatory XKCD link: http://xkcd.com/676/ )

ChrisA


More information about the Python-ideas mailing list