[Python-Dev] Re: Decimal data type issues

Casey Duncan casey at zope.com
Fri Apr 16 09:36:05 EDT 2004


On Fri, 16 Apr 2004 00:17:24 -0400
"Tim Peters" <tim_one at email.msn.com> wrote:

> [Facundo Batista, on whether to limit exponent magnitude]
[..]
> No, I want to spell the spec's mandatory from-string *operation*
> (which does use and affect context, in the specified ways) via an
> optional bool argument to the Decimal constructor.  This isn't at all
> useless, although if you're only thinking about a money type it may
> seem that way.  In general number-crunching, literals may be given to
> high precision, but that precision isn't free and *usually* isn't
> needed:  the operations in the spec don't round back inputs to current
> context precision before computing, they only round outputs after, and
> digits feeding into computation are expensive. So, in general, a
> scientific user will usually *not* want all the digits in
> 
>     pi = Decimal("3.1415926535897932384626433832795",
>     use_context=True)
> 
> to be used.  Instead they'll want to set the working precision once in
> context, and have their literals automatically get rounded back to
> that precision.  
[..]

I find boolean arguments a general anti-pattern, especially given we
have class methods. Why not use an alternate constructor like::

  pi = Decimal.rounded_to_context("3.1415926535897932384626433832795")

Spelling notwithstanding.

-Casey




More information about the Python-Dev mailing list