On Fri, Mar 7, 2014 at 8:16 PM, Chris Angelico email@example.com wrote:
On Sat, Mar 8, 2014 at 3:11 PM, Guido van Rossum firstname.lastname@example.org wrote:
How is Decimal==float implemented? Is it by calling Decimal(rhs) and then comparing? If so, changing how Decimal(float) works won't break the invariant, as it'll make the same conversion each time.
There's a special function to convert the other operand for the purpose of comparisons, and it currently uses Decimal.from_float(). I am not (yet :-) proposing to change the behavior of that function -- it is and has always been the API function that does exact float-to-Decimal conversion. 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.
Maybe not a deal breaker, but certainly another panel on the bikeshed. It would make good sense to retain that invariant by making the comparison use repr just like the constructor.
Not sure I agree. I find the invariant Decimal(x) == x rather uninteresting. I find the idea that Decimal.__eq__ compares the exact mathematical values very appealing.
-- --Guido van Rossum (python.org/~guido)