Author: Armin Rigo <[email protected]>
Branch:
Changeset: r75810:690f33fb3b3e
Date: 2015-02-10 19:27 +0100
http://bitbucket.org/pypy/pypy/changeset/690f33fb3b3e/
Log: The float-list strategy needs to be slightly more careful about NaNs
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1670,6 +1670,25 @@
def getitems_float(self, w_list):
return self.unerase(w_list.lstorage)
+ def _safe_find(self, w_list, obj, start, stop):
+ from rpython.rlib.rfloat import isnan
+ from rpython.rlib.longlong2float import float2longlong
+ #
+ l = self.unerase(w_list.lstorage)
+ stop = min(stop, len(l))
+ if not isnan(obj):
+ for i in range(start, stop):
+ val = l[i]
+ if val == obj:
+ return i
+ else:
+ search = float2longlong(obj)
+ for i in range(start, stop):
+ val = l[i]
+ if float2longlong(val) == search:
+ return i
+ raise ValueError
+
class BytesListStrategy(ListStrategy):
import_from_mixin(AbstractUnwrappedStrategy)
diff --git a/pypy/objspace/std/test/test_listobject.py
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -1565,6 +1565,18 @@
assert l[::11] == [-sys.maxint, item11]
assert item11 in l[::11]
+ def test_bug_list_of_nans(self):
+ N = float('nan')
+ L1 = [N, 'foo'] # general object strategy
+ assert N in L1
+ assert L1.index(N) == 0
+ assert L1 == [N, 'foo']
+ # our float list strategy needs to consider NaNs are equal!
+ L2 = [N, 0.0] # float strategy
+ assert N in L2
+ assert L2.index(N) == 0
+ assert L2 == [N, -0.0]
+
class AppTestListObjectWithRangeList(AppTestListObject):
"""Run the list object tests with range lists enabled. Tests should go in
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit