[Python-Dev] Mixing float and Decimal -- thread reboot

Mark Dickinson dickinsm at gmail.com
Mon Mar 22 19:26:10 CET 2010

On Mon, Mar 22, 2010 at 5:56 PM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> On Mar 22, 2010, at 10:00 AM, Guido van Rossum wrote:
>   Decimal + float --> Decimal
> If everybody associated with the Decimal implementation wants this I
> won't stop you; as I repeatedly said my intuition about this one (as
> opposed to the other two above) is very weak.
> That's my vote.
> I believe Nick chimed-in in agreement.
> Mark, do you concur?

Yes;  Decimal + float -> Decimal works for me; the greater flexibility
of the Decimal type is the main plus for me.  I don't think my own
intuition is particularly strong here, either.  It would be
interesting to hear from major users of the decimal module (I have to
confess to not actually using it myself very much).

I argued earlier for Decimal + float -> Decimal on the basis that the
float->Decimal conversion can be done exactly;  but having thought
about Decimal + Fraction it's no longer clear to me that this makes
sense.  Having Decimal + float -> Decimal round the float using the
current Decimal context still seems like a reasonable option.

Just for the record, I'd also prefer Decimal + Fraction -> Decimal.

I don't want to let the abstractions of the numeric tower get in the
way of the practicalities:  we should modify the abstractions if
necessary!  In particular, it's not clear to me that all numeric types
have to be comparable with each other.  It might make sense for
Decimal + complex mixed-type operations to be disallowed, for example.


More information about the Python-Dev mailing list