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

Greg Ewing greg.ewing at canterbury.ac.nz
Fri May 20 06:28:20 CEST 2005


Tim Peters wrote:
> [Raymond Hettinger]

>>>>>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")
> 
> the results differ here because D(whatever)
> ignores context settings; having a common operation ignore context is
> ugly and error-prone).

I don't see it's because of that. Even if D(whatever)
didn't ignore the context settings, you'd get the same
oddity if the numbers came from somewhere else with a
different precision.

I'm very uncomfortable about the whole idea of a
context-dependent precision. It just seems to be
asking for trouble.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list