[Python-Dev] Decimal data type issues

Batista, Facundo FBatista at uniFON.com.ar
Thu Apr 15 09:27:17 EDT 2004


[Tim Peters]

#- [Facundo Batista, on max exponent]
#- > But it's still an artificial restriction.  We have no-limit longs,
#- > should have limited Decimal?
#- 
#- Nobody has a use for unbounded exponents, so it's a silly 
#- thing to support
#- if there are costs.  There are costs, including:
#- 
#- + As mentioned last time, eliminating bounds on exponents effectively
#-   ...
#- + Virtually all implementations of 854 use (and as IBM's 
#-   ...
#- + Big as it is, the IBM standard is a tiny start at supplying a
#-   ...

The feeling previous to this mail was that an artificial limit was silly if
you don't gain nothing.

Here are three valuable reasons for keep the limits.

So, if nobody opposes strongly, I'll put these reasons in the PEP and keep
the limit.



#- > not creations (with the exception of from_string).
#- 
#- I don't understand.  The only place the spec uses the word 
#- "creation" is in
#- regard to the creation of context objects.  What do you mean 
#- by "creations"?
#- Context does affect every way of creating a decimal number 
#- in the spec; the
#- only ways to create numbers covered by the spec are via 
#- operations (and
#- from_string isn't a special case here, from_string is just one of the
#- required operations in the spec, and all operations covered 
#- by the spec
#- respect context).

Until now, Decimal does not uses context in creation time (with creation I
mean when you create an object instantiating the class).

This allows to not lose any information at creation time, and only use the
context in operations.

Do you want to change this behaviour?



#- > I'm lost here. Are you saying that str() should have the 
#- same behaviour
#- > that to_sci_string()?
#- 
#- Yes, that str(Decimal) should produce exactly the string the 

Ok.


#- supplied.  The
#- meaning of to-sci-string is precisely specified by the 
#- standard, and is a
#- good choice for both str(Decimal) and repr(Decimal).  (It's both
#- human-readable and exact.)

The only issue *I* see here, is that you don't have a clear representation
of the internals of the object, but yes, you have an exact representation of
that number. Let me show an example:

>>> d = Decimal.Decimal((1, (1,2,3,4,0), 1))
>>> d
Decimal( (1, (1, 2, 3, 4, 0), 1L) )
>>> d.to_sci_string()
'-1.2340E+5'

There you have to count the decimals and use the exponent in the string to
know what the real exponent is (but I don't know how much important this
is).

.	Facundo



More information about the Python-Dev mailing list