[Python-Dev] [Python-checkins] python/nondist/peps pep-0343.txt, 1.11, 1.12

Tim Peters tim.peters at gmail.com
Wed May 18 06:28:18 CEST 2005


[Raymond Hettinger]
> ...
> One more change:  The final "return +s" should be unindented.  It should
> be at the same level as the "do with_extra_precision()".  The purpose of
> the "+s" is to force the result to be rounded back to the *original*
> precision.
>
> This nuance is likely to be the bane of folks who shift back and forth
> between different levels of precision.

Well, a typical user will never change precision most of the time.  Of
the remaining uses, most will set precision once at the start of the
program, and never change it again.  Library authors may change
precision frequently, but they should be experts.

> The following example shows the kind of oddity that can arise when
> working with quantities that have not been rounded to the current precision:
>
> >>> from decimal import getcontext, Decimal as D
> >>> getcontext().prec = 3
> >>> D('3.104') + D('2.104')
> Decimal("5.21")
> >>> D('3.104') + D('0.000') + D('2.104')
> Decimal("5.20")

I think it shows more why it was a mistake for the decimal constructor
to extend the standard (the string->decimal operation in the standard
respects context settings; the results differ here because D(whatever)
ignores context settings; having a common operation ignore context is
ugly and error-prone).


More information about the Python-Dev mailing list