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

Antoine Pitrou solipsis at pitrou.net
Sat Mar 20 16:11:12 CET 2010


Mark Dickinson <dickinsm <at> gmail.com> writes:
> 
> On Fri, Mar 19, 2010 at 9:50 PM, Guido van Rossum <guido <at> python.org>
wrote:
> > There is one choice which I'm not sure about. Should a mixed
> > float/Decimal operation return a float or a Decimal?
> 
> I'll just say that it's much easier to return a Decimal if you want to
> be able to make guarantees about rounding behaviour, basically because
> floats can be converted losslessly to Decimals.  I also like the fact
> that the decimal module offers more control (rounding mode, precision,
> flags, wider exponent range) than float.

A problem, though, is that decimals are much slower than floats. If you have a
decimal creeping in some part of a calculation it could degrade performance
quite a bit.

Regards

Antoine.




More information about the Python-Dev mailing list