Message84433
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:18 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, facundobatista, jdunck, lorg |
2009-03-29 21:42:18 | mark.dickinson | set | messageid: <1238362938.36.0.970997186173.issue2531@psf.upfronthosting.co.za> |
2009-03-29 21:42:17 | mark.dickinson | link | issue2531 messages |
2009-03-29 21:42:16 | mark.dickinson | create | |
|