[Python-Dev] Decimal data type issues

Batista, Facundo FBatista at uniFON.com.ar
Fri Apr 16 09:07:09 EDT 2004


[Ka-Ping Yee]

#- On Thu, 15 Apr 2004, Batista, Facundo wrote:
#- >...
#- > Here I think you're confused. *Precision* is a parameter 
#- of the context, and
#- > determines in how many digits you will get the coefficient after an
#- > operation.
#- >
#- > The issue when constructing from float, is how many 
#- *positions* after the
#- > decimal point will be relevant when creating from a float.
#- 
#- I never mentioned positions, and i don't see any reason why it is
#- necessary to isolate these two ways of specifying precision. 

Because they are two totally different concepts. And they're not two ways of
specifying precision.

Precision is the maximum of significant digits the number can have. And
positions is the number of digits after the decimal point at which you want
to round the number you're creating from and discard the other digits.


#-  Sometimes
#- it will be useful to specify a number of significant digits and other
#- times it will be useful to specify a number of digits after 
#- the decimal
#- point.  Both kinds of specification are useful as a context 
#- for arithmetic
#- operations and useful when constructing from any type 
#- including float.
#- 
#- So it would be nice if contexts were able to specify 
#- precision in either
#- fashion.

Well. If you want the positions to be included in the context to be used in
arithmetic operations, you're out of spec. And the PEP is for implementing
the "General Decimal Arithmetic Specification", so the answer to that is NO.


#- But that is a separate issue from the one i was trying to raise.  To
#- bring up this precision vs. position question is to miss my point.
#- 
#- Here is my point, again: Decimal(1.1, significant_digits=4) 
#- is unambiguous.

I don't think so. For example: 

>>> d = Decimal.Decimal.from_float(25364.1254)
>>> str(d)
'25364.12540000000080908648669719696044921875'

What whould mean here "significant_digits=4"?

  To have '2536E2'? You use "precision" to achieve this.
  To have '25364.1254'? You use "position" in from_float method to achieve
this.


#- Converting from float is not confusing when the precision is 
#- specified
#- (either in terms of significant digits or decimal places).

Don't confuse the terminology. Precision means only one thing, and it's
specified in Cowlishaw work. You can not change that. Maybe all the
discussion doesn't make sense if we talk about different things.


#- I want to supply a context for constructing the Decimal value.

I'm +1 with this. But the context that you supply affect the PRECISION to be
used. It has nothing to do with POSITIONS.

.	Facundo



More information about the Python-Dev mailing list