[Python-Dev] Decimal data type issues (original) (raw)

Ka-Ping Yee python-dev at zesty.ca
Fri Apr 16 05:14:36 EDT 2004


On Thu, 15 Apr 2004, Batista, Facundo wrote:

[Ka-Ping Yee]

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

So the user can specify how much precision the resulting Decimal value should have.

#- I assume the purpose of fromfloat 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.

I never mentioned positions, and i don't see any reason why it is necessary to isolate these two ways of specifying precision. 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.

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.

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

Therefore, it is not necessary to make all float conversions inconvenient. It is only necessary to make exact float conversions inconvenient.

Focusing on the true source of the problem also lets us use a more descriptive name for this special case.

#- 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?

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

It would not be persistent. You would use some other method (presumably something you have already conceived and named) for setting the Decimal context for the entire thread.

-- ?!ng



More information about the Python-Dev mailing list