[pypy-svn] r69444 - in pypy/trunk/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Nov 19 14:59:52 CET 2009
Author: arigo
Date: Thu Nov 19 14:59:51 2009
New Revision: 69444
Modified:
pypy/trunk/pypy/objspace/std/floatobject.py
pypy/trunk/pypy/objspace/std/test/test_floatobject.py
Log:
Always return 0 for hash(nan). Fixes an issue with
calling int(nan), on some versions of Python.
Modified: pypy/trunk/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/floatobject.py (original)
+++ pypy/trunk/pypy/objspace/std/floatobject.py Thu Nov 19 14:59:51 2009
@@ -2,7 +2,7 @@
from pypy.interpreter import gateway
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.longobject import W_LongObject
-from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask, isinf
+from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask, isinf, isnan
from pypy.rlib.rarithmetic import formatd
import math
@@ -197,6 +197,9 @@
def _hash_float(space, v):
from pypy.objspace.std.longobject import hash__Long
+ if isnan(v):
+ return 0
+
# This is designed so that Python numbers of different types
# that compare equal hash to the same value; otherwise comparisons
# of mapping keys will turn out weird.
Modified: pypy/trunk/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_floatobject.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_floatobject.py Thu Nov 19 14:59:51 2009
@@ -59,10 +59,7 @@
inf = 1e200 * 1e200
assert hash(inf) == 314159
assert hash(-inf) == -271828
- x = hash(inf/inf)
- # ^^^ assert did not crash, even though the result is a bit random
- # e.g. it appears to be -32768 on Win32 and 0 on Linux
- assert x == hash(inf/inf)
+ assert hash(inf/inf) == 0
def test_int_float(self):
assert int(42.1234) == 42
More information about the Pypy-commit
mailing list