[Python-Dev] Decimal <-> float comparisons in py3k.

Antoine Pitrou solipsis at pitrou.net
Thu Mar 18 19:44:52 CET 2010


Glenn Linderman <v+python <at> g.nevcal.com> writes:
> 
> For all the reasons that mixed decimal and float arithmetic is bad, 
> mixed decimal and float comparisons are also bad.  To do proper 
> comparisons, you need to know the number of significant digits of both 
> numbers, and the precision and numeric ranges being dealt with by the 
> application.

What is a "proper comparison"?
A comparison is a lossy operation by construction (it returns only 1 bit of
output, or 2 bits for rich comparison), so the loss in precision that results
from mixing float and decimal operands should not be a concern here.

Unless there are situations where the comparison algorithm might return wrong
results (are there?), I don't see why we should forbid such comparisons.

> Seems like it would be better to raise an exception, and in the 
> documentation for the exception point out that turning off the exception 
> (if it should be decided that that should be possible, which could be 
> good for compatibility), would regress to the current behavior, which 
> doesn't sort numerically, but by type.

Regressing to an useless behaviour sounds like a deliberate annoyance. I don't
think this proposal should be implemented.

Regards

Antoine.




More information about the Python-Dev mailing list