diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-02-08 14:42:28 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-02-08 14:42:28 (GMT) |
commit | 10fe877dcd547befa3114e52f180bacf98e56098 (patch) | |
tree | 8d838a1ebd8bf9034d6199a8042b8ad54914821b /Objects | |
parent | c5e68b1898bde52ad8af73d21a8abd7461317302 (diff) | |
download | cpython-10fe877dcd547befa3114e52f180bacf98e56098.zip cpython-10fe877dcd547befa3114e52f180bacf98e56098.tar.gz cpython-10fe877dcd547befa3114e52f180bacf98e56098.tar.bz2 |
Issue #789290: make sure that hash(2**63) == hash(2.**63) on 64-bit
platforms. The previous code was fragile, depending on the twin
accidents that:
(1) in C, casting the double value 2.**63 to long returns the integer
value -2**63, and
(2) in Python, hash(-2**63) == hash(2**63).
There's already a test for this in test_hash.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c index ba736a9..9108fd4 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1028,7 +1028,7 @@ _Py_HashDouble(double v) fractpart = modf(v, &intpart); if (fractpart == 0.0) { /* This must return the same hash as an equal int or long. */ - if (intpart > LONG_MAX || -intpart > LONG_MAX) { + if (intpart > LONG_MAX/2 || -intpart > LONG_MAX/2) { /* Convert to long and use its hash. */ PyObject *plong; /* converted to Python long */ if (Py_IS_INFINITY(intpart)) |