[Python-ideas] Python Numbers as Human Concept Decimal System

Tim Peters tim.peters at gmail.com
Sat Mar 8 05:39:59 CET 2014


[Guido]
> Decimal(repr(f)) == f returns False today (for the majority of float values
> anyway) and under my proposal Decimal(f) == f would also return False. I
> don't (yet :-) think that's a deal breaker.

To the contrary, that's "a feature".  Current Pythons take equality
testing seriously, striving to return True when & only when values are
mathematically ("as if using infinite precision") identical, even when
that's inconvenient to do:

>>> 2**500 == 2.0**500
True
>>> 2**500 + 1 == 2.0**500
False

If information is lost when converting, it's doing nobody a favor for
"==" to pretend it hasn't been lost.  So long as Decimal.from_float(f)
== f is still True, then equality would be working as expected in all
cases.


More information about the Python-ideas mailing list