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

Michael Chermside mcherm at mcherm.com
Tue Apr 13 15:31:16 EDT 2004


Facundo Batista writes:

Exponent Maximum ---------------- [...] The exponent is an integer, and in the actual implementation exists a maximum value::

DEFAULTMAXEXPONENT = 999999999 DEFAULTMINEXPONENT = -999999999 ABSOLUTEMAXEXP = 999999999 ABSOLUTEMINEXP = -999999999 The issue is that this limit is artificial: [...] So, should we impose an artificial limit to the exponent? This is important, as there're several cases where this maximums are checked and exceptions raised and/or the numbers get changed.

I strongly prefer for my programming language not to impose aribtrary limits, however, I can't see myself using decimal to represent numbers with 1 billion digits. So IMHO, I would avoid the limit if possible, but if imposing the limit permitted substantial code simplification or performance improvements then I wouldn't complain. Much.

New operations --------------

Tim Peters found I missed three operations required by the standard.

Sure. Your proposal sounds good.

Hash behaviour -------------- [...] In the PEP I wrote that Decimal must be hashable. But what hash should it give?

Should the following be true?:: hash(Decimal(25) == hash(25) hash(Decimal.fromfloat(25.35) == hash(25.35) hash(Decimal('-33.8')) == hash(-33.8) I don't think so. I think that hash(Decimal(...)) just should return a different value in each case, but no the same value that other data types.

I disagree. If x == y, then that should imply that hash(x) == hash(y). So hash(Decimal(25)) == hash(25) had better be true. On the other hand, hash(Decimal('-33')) CANNOT equal hash(Decimal('-33')), since the latter must equal hash(-33). And I'm not particularly concerned about floats... if it's easy to make the hashes equal for those few numbers which can be expressed EXACTLY as both a (binary) float and a (decimal) Decimal, then that's be "kinda nice", but since there are so few values which can be expressed exactly as both a float and a Decimal, I don't see it as a big issue.

-- Michael Chermside



More information about the Python-Dev mailing list