[Python-Dev] Python's C interface for types
"Martin v. Löwis"
martin at v.loewis.de
Sat Jan 27 00:43:06 CET 2007
Nick Maclaren schrieb:
>> I personally consider *very* important that hash(5.0) == hash(5) (and
>> that 5.0 == 5, of course).
>
> It gets a bit problematic with floating-point, when you can have
> different values "exactly 5.0" and "approximately 5.0". IEEE 754
> has signed zeroes. And so it goes.
[not sure what "And so it goes" means in English]
It may be a bit problematic to implement, but I think a clean
specification is possible. If a and b are numbers, and a==b,
then hash(a)==hash(b). I'm not sure whether "approximately 5.0"
equals 5 or not: if it does, it should hash the same as 5,
if it doesn't, it may or may not hash the same (whatever is
easier to implement).
For 0: hash(+0.0)==hash(-0.0)==hash(0)=hash(0L)=0
Regards,
Martin
More information about the Python-Dev
mailing list