Re: [Python-Dev] Python's C interface for types
Giovanni Bajo <rasky@develer.com> wrote:
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. Regards, Nick Maclaren, University of Cambridge Computing Service, New Museums Site, Pembroke Street, Cambridge CB2 3QH, England. Email: nmm1@cam.ac.uk Tel.: +44 1223 334761 Fax: +44 1223 334679
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
participants (2)
-
"Martin v. Löwis"
-
Nick Maclaren