Comparing float and decimal

Mark Dickinson dickinsm at gmail.com
Wed Sep 24 06:14:38 EDT 2008


On Sep 23, 7:31 pm, Terry Reedy <tjre... at udel.edu> wrote:
> Decimal is something of an anomaly in Python because it was written to
> exactly follow an external standard, with no concessions to what would
> be sensible for Python.  It is possible that that standard mandates that
> Decimals not compare to floats.

I don't think the standard says anything about interactions between
Decimals and floats.  But there's certainly been a feeling amongst at
least some of the developers that the job of Python's decimal module
is
to implement the standard and no more, and that extensions to its
functionality belong elsewhere.

Regarding equality, there's at least one technical issue:  the
requirement
that objects that compare equal hash equal.  How do you come up with
efficient hash operations for integers, floats, Decimals and Fractions
that satisfy this requirement?

For other arithmetic operations:  should the sum of a float and a
Decimal
produce a Decimal or a float?  Why?  It's not at all clear to me that
either of these types is 'higher up' the numerical tower than the
other.

Mark



More information about the Python-list mailing list