On Fri, Mar 7, 2014 at 8:39 PM, Tim Peters firstname.lastname@example.org wrote:
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:
2500 == 2.0500 True 2500 + 1 == 2.0500 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.
I agree. But what do you think of my main proposal? I would retract it if you advised me so.
-- --Guido van Rossum (python.org/~guido)