Skip to content

Commit 120a18d

Browse files
author
mark.dickinson
committedFeb 8, 2009
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. git-svn-id: http://svn.python.org/projects/python/trunk@69436 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 5eaa3f8 commit 120a18d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎Objects/object.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ _Py_HashDouble(double v)
10281028
fractpart = modf(v, &intpart);
10291029
if (fractpart == 0.0) {
10301030
/* This must return the same hash as an equal int or long. */
1031-
if (intpart > LONG_MAX || -intpart > LONG_MAX) {
1031+
if (intpart > LONG_MAX/2 || -intpart > LONG_MAX/2) {
10321032
/* Convert to long and use its hash. */
10331033
PyObject *plong; /* converted to Python long */
10341034
if (Py_IS_INFINITY(intpart))

0 commit comments

Comments
 (0)
Please sign in to comment.