[Python-Dev] Decimal <-> float comparisons in py3k. (original) (raw)

Glenn Linderman v+python at g.nevcal.com
Fri Mar 19 00:25:53 CET 2010


On 3/18/2010 2:48 PM, Nick Coghlan wrote:

When there is a clear, correct way (based on Decimal.fromfloat) to make numeric comparison behave in accordance with the rules of mathematics, do we really want to preserve strange, unintuitive behaviour like the above?

Cheers, Nick.

I'm aware of nothing that prevents the lazy coder from having a class unifiedNumber in his toolbox that implements his favorite type of conversions from various numeric types to whatever he thinks is the "best" one for his application, and then using it places where sources might be of various other numeric types. I'm aware of nothing that would prevent the lazy coder from implement comparison operators and even arithmetic operators on such a class.

I believe, but haven't proven, and haven't used Python long enough to "just know", that such class could even implement what would appear to be operators that would seem to provide implicit conversion from the various other numeric classes, as long as one item was of the class.

So I think it would be possible, with such a class, to have one's cake (nothing implicit), and eat it too (providing a way do comparisons and numerical operations, mostly implicitly).

Glenn



More information about the Python-Dev mailing list