[Python-Dev] Re: [Patches] fix float_hash and complex_hash for 64-bit *nix

Guido van Rossum guido@python.org
Thu, 11 May 2000 09:01:10 -0400

I have to admit I have no clue about the details of this debate any
more, and I'm cowardly awaiting a patch submission that Tim approves
of.  (I'm hoping a day will come when Tim can check it in himself. :-)

In the mean time, I'd like to emphasize the key invariant here: we
must ensure that (a==b) => (hash(a)==hash(b)).  One quick way to deal
with this could be the following pseudo C:

    PyObject *double_hash(double x)
        long l = (long)x;
        if ((double)l == x)
	    return long_hash(l);
	...double-specific code...

This code makes one assumption: that if there exists a long l equal to
a double x, the cast (long)x should yield l...

--Guido van Rossum (home page: http://www.python.org/~guido/)