Phillip writes:
> >@do_template
> >def with_extra_precision(places=2):
> > "Performs nested computation with extra digits of precision."
> > decimal.getcontext().prec += 2
> > yield None
> > decimal.getcontext().prec -= 2
>
> Won't this do the wrong thing if something within the blo
Guido van Rossum wrote:
> Anyway, perhaps we should provide this most general template:
>
> @do_template
> def with_decimal_context():
> oldctx = decimal.getcontext()
> newctx = oldctx.copy()
> decimal.setcontext(newctx)
> yield newctx
> decimal.setcontext(oldctx)
On May 17, 2005, at 11:39 PM, Guido van Rossum wrote:
> [Raymond Hettinger]
>
>> However, for a general purpose wrapper, it is preferable to make a
>> context copy and then restore the context after the enclosed is run.
>> That guards against the enclosed block making any unexpected context
>> ch
[Raymond Hettinger]
> The sin() example is correct. The precision is changed and restored in
> the current context.
I got that eventually. :-)
> However, for a general purpose wrapper, it is preferable to make a
> context copy and then restore the context after the enclosed is run.
> That guards
> I don't see a call to setcontext() in the sin() example in the library
> reference. Is that document wrong? I thought that simply modifying the
> parameters of the current context would be sufficient.
The sin() example is correct. The precision is changed and restored in
the current context.
H
On May 17, 2005, at 10:36 PM, Guido van Rossum wrote:
> On 5/17/05, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>
>>> I think you're missing a decimal.setcontext(newcontext) before the
>>> yield..
>>>
>>
>> Right.
>>
>
> I don't see a call to setcontext() in the sin() example in the library
> re
On 5/17/05, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> > I think you're missing a decimal.setcontext(newcontext) before the
> > yield..
>
> Right.
I don't see a call to setcontext() in the sin() example in the library
reference. Is that document wrong? I thought that simply modifying the
para
> I think you're missing a decimal.setcontext(newcontext) before the
> yield..
Right.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/arc
Bob Ippolito wrote:
>> One more thought: Rather than just saving the precision, it is
>> likely wiser, safer, and more general to just save and restore the
>> whole context and let the wrapped block only work with a copy.
>>
>> oldcontext = decimal.getcontext()
>> newcontext = oldcontext
On May 17, 2005, at 9:02 PM, Raymond Hettinger wrote:
>>> What's the advantage of using two calls to getcontext() vs. saving
>>>
> the
>
>>> context in a local variable?
>>>
>>
>> I also prefer saving the context in a local variable but that is just
>>
> a
>
>> micro-optimization. The presentati
> > What's the advantage of using two calls to getcontext() vs. saving
the
> > context in a local variable?
>
> I also prefer saving the context in a local variable but that is just
a
> micro-optimization. The presentation with multiple calls to
> getcontext() was kept just to match the style of
> What's the advantage of using two calls to getcontext() vs. saving the
> context in a local variable?
I prefer saving the context in a local variable but that is just a
micro-optimization. The presentation with multiple calls to
getcontext() was kept just to match the style of the original -- t
TECTED] On Behalf Of Phillip J. Eby
> > Sent: Tuesday, May 17, 2005 6:06 PM
> > To: Michael Chermside; [EMAIL PROTECTED]
> > Cc: python-dev@python.org
> > Subject: Re: [Python-Dev] Example for PEP 343
> >
> > At 02:42 PM 5/17/2005 -0700, Michael Chermside wrote:
&g
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-dev-
> [EMAIL PROTECTED] On Behalf Of Phillip J. Eby
> Sent: Tuesday, May 17, 2005 6:06 PM
> To: Michael Chermside; [EMAIL PROTECTED]
> Cc: python-dev@python.org
> Subject: Re: [Python-Dev] Example for PEP
At 02:42 PM 5/17/2005 -0700, Michael Chermside wrote:
># = SAMPLE #1: increasing precision during a sub-calculation =
>
>import decimal
>
>@do_template
>def with_extra_precision(places=2):
> "Performs nested computation with extra digits of precision."
> decimal.getcontext().prec +
In PEP 343 Guido writes:
>8. Another use for this feature is the Decimal context. It's left
> as an exercise for the reader. (Mail it to me if you'd like to
> see it here.)
Here are two such examples. Pick your favorite for the PEP.
PS: Writing this helped convince me that allow
16 matches
Mail list logo