[Python-Dev] Decimal & amp; lt; -& amp; gt; float comparisons in py3k.

Terry Reedy tjreedy at udel.edu
Fri Mar 19 19:43:01 CET 2010

On 3/19/2010 2:11 PM, Antoine Pitrou wrote:
> Raymond Hettinger<raymond.hettinger<at>  gmail.com>  writes:
>> The reason to prefer an exception is that decimal/float comparisons
>> are more likely to be a programmer error than an intended behavior.

If you really believe that, then equality comparisons should also be 
disabled by raising NotImplemented or whatever. Clearly, someone who 
writes 'if somefloat == somedecimal:'assumes (now wrongly) that the test 
might be true. This is just as buggy as an order comparison. Raising an 
exception would consistently isolate decimals from other numbers and 
eliminate the equality intransitivity mess and its nasty effect on sets.

It still strikes me as a bit crazy for Python to say that 0.0 == 0 and 0 
== Decimal(0) but that 0.0 != Decimal(0). Who would expect such a thing?

Terry Jan Reedy

More information about the Python-Dev mailing list