[Python-Dev] Revised decimal type PEP

Michael McLay mclay@nist.gov
Tue, 31 Jul 2001 03:40:21 -0400

On Tuesday 31 July 2001 12:37 pm, Aahz Maruch wrote:
> Michael McLay wrote:

> > For addition, subtraction, and multiplication the results would be
> > exact with no rounding of the results.  Calculations that include
> > division the number of digits in a non-terminating result will have to
> > be explicitly set.  Would it make sense for this to be definedby the
> > numbers used in the calculation?  Could this be set in the module or
> > could it be global for the application?
> This is why Cowlishaw et al require a full context for all operations.
> At one point I tried implementing things with the context being
> contained in the number rather than "global" (which actually means
> thread-global, but I'm probably punting on *that* bit for the moment),
> but Tim Peters persuaded me that sticking with the spec was the Right
> Thing until *after* the spec was fully implemented.
> After seeing the mess generated by PEP-238, I'm fervently in favor of
> sticking with external specs whenever possible.

I had originally expected the context for decimal calculations to be the 
module in which a statement is defined.  If a function defined in another 
module is called the rules of that other module would be applied to that part 
of the calculation.  My expectations of how Python would work with decimal 
numbers doesn't seem to match what Guido said about his conversation with 
Tim, and what you said in this message.  

How can the rules for using decimals be stated so that a newbie can 
understand what they should expect to happen?  We could set a default 
precision of 17 digits and all calculations that were not exact would be 
rounded to 17 digits.  This would match how their calculator works.  I would 
think this would be the model with the least suprises.  For someone needing 
to be more precise, or less precise, how would this rule be modified?