Author: Armin Rigo <[email protected]>
Branch:
Changeset: r84865:2611d008c62d
Date: 2016-06-01 17:33 +0200
http://bitbucket.org/pypy/pypy/changeset/2611d008c62d/
Log: merge heads
diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -213,6 +213,8 @@
return self_type
if self_type in (bool, int, long):
return other_type
+ if self_type is float or other_type is float:
+ return float
if self_type.SIGNED == other_type.SIGNED:
return build_int(None, self_type.SIGNED, max(self_type.BITS,
other_type.BITS))
raise AssertionError("Merging these types (%s, %s) is not supported" %
(self_type, other_type))
@@ -297,6 +299,7 @@
def _widen(self, other, value):
"""
if one argument is int or long, the other type wins.
+ if one argument is float, the result is float.
otherwise, produce the largest class to hold the result.
"""
self_type = type(self)
diff --git a/rpython/rlib/test/test_rarithmetic.py
b/rpython/rlib/test/test_rarithmetic.py
--- a/rpython/rlib/test/test_rarithmetic.py
+++ b/rpython/rlib/test/test_rarithmetic.py
@@ -18,11 +18,11 @@
class Test_r_int:
def test__add__(self):
- self.binary_test(lambda x, y: x + y)
+ self.binary_test(lambda x, y: x + y, includes_floats=True)
def test__sub__(self):
- self.binary_test(lambda x, y: x - y)
+ self.binary_test(lambda x, y: x - y, includes_floats=True)
def test__mul__(self):
- self.binary_test(lambda x, y: x * y)
+ self.binary_test(lambda x, y: x * y, includes_floats=True)
x = 3; y = [2]
assert x*y == r_int(x)*y
assert y*x == y*r_int(x)
@@ -58,12 +58,15 @@
cmp = f(r_int(arg))
assert res == cmp
- def binary_test(self, f, rargs = None):
+ def binary_test(self, f, rargs=None, includes_floats=False):
if not rargs:
rargs = (-10, -1, 3, 55)
+ types_list = [(int, r_int), (r_int, int), (r_int, r_int)]
+ if includes_floats:
+ types_list += [(float, r_int), (r_int, float)]
for larg in (-10, -1, 0, 3, 1234):
for rarg in rargs:
- for types in ((int, r_int), (r_int, int), (r_int, r_int)):
+ for types in types_list:
res = f(larg, rarg)
left, right = types
cmp = f(left(larg), right(rarg))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit