Author mark.dickinson
Recipients facundobatista, jdunck, lorg, mark.dickinson, rhettinger
Date 2009-03-29.21:42:16
SpamBayes Score 2.62008e-09
Marked as misclassified No
Message-id <>
Removing easy keyword, since I don't think it applies here.

The problem here is hashing:  either we break the rule that
if two objects compare equal then they hash equal, or we
fix hash so that e.g., hash(Decimal('2.5')) == hash(2.5).

For the latter, the least invasive way to do it would be
to fix only the Decimal __hash__ method.  For that, we
really need a Decimal -> float conversion, so that we
can do something like (for a Decimal x):

if x == Decimal.from_float(x.to_float()):
    return hash(x.to_float())
[rest of hash method here]

The builtin float() (which converts a Decimal to a string
and then uses the standard C library's string -> float
conversion) probably isn't good enough for this, since
there are no requirements that it should be (even close to)
correctly rounded.

The bottom line: getting a correctly-rounded
Decimal -> float method, without knowing what
the float format is, is going to be hard.
If we assume IEEE 754 then it's much easier.
Date User Action Args
2009-03-29 21:42:18mark.dickinsonsetrecipients: + mark.dickinson, rhettinger, facundobatista, jdunck, lorg
2009-03-29 21:42:18mark.dickinsonsetmessageid: <>
2009-03-29 21:42:17mark.dickinsonlinkissue2531 messages
2009-03-29 21:42:16mark.dickinsoncreate