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

Steven D'Aprano steve at pearwood.info
Sun Mar 21 23:59:53 CET 2010


On Mon, 22 Mar 2010 06:31:57 am Raymond Hettinger wrote:
> I really like Guido's idea of a context flag to control whether
> mixing of decimal and binary floats will issue a warning.
> The default should be to issue the warning (because unless
> you know what you're doing, it is most likely an error).

When you say "warning", do you mean warning.warn(), or an exception?

I'd like to put in a vote for allowing naive users with low requirements 
for accuracy and precision to be able to type something like this in 
the interactive interpreter:

>>> Decimal(1) + 1.0

and get two (in whatever type is decided on) without having to change 
the context or deal with an exception.

Yes, this means that they may be surprised if they perform an operation 
which suffers from rounding errors, but that's no worse than what 
happens with floats.

If naive users are going to use the interpreter as a calculator, they're 
going to start off using floats and ints simply because they require 
less typing. My idea is to allow a gentle learning curve with Decimal 
(and Fraction) without scaring them off with exceptions or excessive 
warnings: a single warning per session would be okay, a warning after 
every operation would be excessive in my opinion, and exceptions by 
default would be right out.



-- 
Steven D'Aprano


More information about the Python-Dev mailing list