[Python-Dev] Decimal data type issues

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


[Ka-Ping Yee]

#- Aren't you going to need an optional argument anyway to let the
#- user specify a context?

What for?


#- I assume the purpose of from_float is to prevent people from being
#- confused about whether Decimal(1.1) produces exactly 1.1 or 
#- the machine
#- value of the double-precision rounded float closest to 1.1.  Is that
#- correct?
#- 
#- If so, then the real exceptional case is *exact* conversion, 
#- not float
#- conversion.  Decimal(1.1, precision=4) is unambiguous.  Therefore:

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.

This list agreed to have a special method to creating from float, to avoid
confusing users about the real behaviour there. And in that method only you
permit to specify the positions. When constructing from other data types,
positions does not have any meaning as those other data types are always
exact.


#- The extra method should be specifically for the exceptional case,
#- and named appropriately.
#- 
#-     Decimal.exact_float(value)
#- 
#- It would serve just one purpose: allow exact conversion from floats
#- when it's really desired.
#- 
#- This would both (a) separate the functionality between Decimal()
#- and Decimal.exact_float() in a more logical way; and (b) give
#- the extra method a more meaningful, useful name -- a name that
#- really explains why the extra method exists.

I think that *maybe* a better name is needed, but just that.


#- > Also, remember that the context doesn't affect the 
#- creation when you create
#- > directly from string (only if you use from_string).  Your 
#- example means to
#- > change the behaviour of the creation when creating 
#- directly from string? And
#- > when create directly from int or long?
#- 
#- That's what I'm suggesting: that you can supply a context object,
#- or ask for the default context, when constructing any Decimal value.

Do you want to supply a context that *will affect* the creation process, or
just supply one that the Decimal will keep to use in other operations?

Remember that you have one context per thread.  All the decimal instances in
a thread share the same context.  This was specified by Aahz, the list
agreed, and get into the PEP. Do you want to change it?

.	Facundo



More information about the Python-Dev mailing list