[pypy-svn] r68512 - in pypy/branch/gc-hash/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Thu Oct 15 21:37:00 CEST 2009


Author: arigo
Date: Thu Oct 15 21:36:59 2009
New Revision: 68512

Modified:
   pypy/branch/gc-hash/pypy/rpython/rfloat.py
   pypy/branch/gc-hash/pypy/rpython/test/test_rfloat.py
Log:
Remove duplication of code, and fix a test.


Modified: pypy/branch/gc-hash/pypy/rpython/rfloat.py
==============================================================================
--- pypy/branch/gc-hash/pypy/rpython/rfloat.py	(original)
+++ pypy/branch/gc-hash/pypy/rpython/rfloat.py	Thu Oct 15 21:36:59 2009
@@ -10,6 +10,7 @@
 from pypy.rpython.rmodel import log
 
 from pypy.rlib.rarithmetic import base_int
+from pypy.rlib.objectmodel import _hash_float
 
 import math
 
@@ -109,7 +110,7 @@
     get_ll_le_function = get_ll_eq_function
 
     def get_ll_hash_function(self):
-        return ll_hash_float
+        return _hash_float
 
     def rtype_is_true(_, hop):
         vlist = hop.inputargs(Float)
@@ -142,22 +143,6 @@
         pass
     ll_str._annspecialcase_ = "specialize:ts('ll_str.ll_float_str')"
 
-
-TAKE_NEXT = float(2**31)
-
-def ll_hash_float(f):
-    """
-    this implementation is identical to the CPython implementation,
-    despite the fact that the integer case is not treated, specially.
-    This should be special-cased in W_FloatObject.
-    In the low-level case, floats cannot be used with ints in dicts, anyway.
-    """
-    v, expo = math.frexp(f)
-    v *= TAKE_NEXT
-    hipart = int(v)
-    v = (v - float(hipart)) * TAKE_NEXT
-    x = hipart + int(v) + (expo << 15)
-    return x
 #
 # _________________________ Conversions _________________________
 

Modified: pypy/branch/gc-hash/pypy/rpython/test/test_rfloat.py
==============================================================================
--- pypy/branch/gc-hash/pypy/rpython/test/test_rfloat.py	(original)
+++ pypy/branch/gc-hash/pypy/rpython/test/test_rfloat.py	Thu Oct 15 21:36:59 2009
@@ -4,6 +4,7 @@
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_singlefloat,\
      isnan, isinf
+from pypy.rlib.objectmodel import compute_hash
 
 class TestSnippet(object):
 
@@ -145,9 +146,9 @@
 
     def test_hash(self):
         def fn(f):
-            return hash(f)
+            return compute_hash(f)
         res = self.interpret(fn, [1.5])
-        assert res == hash(1.5)
+        assert res == compute_hash(1.5)
 
 
 class TestOOtype(BaseTestRfloat, OORtypeMixin):



More information about the Pypy-commit mailing list