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

Raymond Hettinger raymond.hettinger at gmail.com
Fri Mar 19 19:42:42 CET 2010


On Mar 19, 2010, at 11:11 AM, 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.
> 
> Not more so than float/int or decimal/int or bool/int comparisons, which all 
> work.

The float/int and decimal/int comparisons have valid and common use cases.
In contrast, comparing binary floats and decimal floats is rare, and more 
likely to be an accident.

When an int is converted to a float or decimal, the result usually isn't
surprising.  The conversion of a float to a decimal is not as straight-forward
(most people don't even know that an exact conversion is possible).

Also, the float and decimal constructors also natively accept ints as inputs,
but the decimal constructor intentionally excludes a float input.


Raymond





More information about the Python-Dev mailing list