Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r88226:a23c22636d73
Date: 2016-11-08 19:37 +0100
http://bitbucket.org/pypy/pypy/changeset/a23c22636d73/

Log:    We want r_longlong(42) + 0.5 to be 42.5. Previous version returned
        42.0...

diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -323,50 +323,48 @@
 
     def __add__(self, other):
         x = long(self)
-        y = long(other)
+        y = other      # may be a float
         return self._widen(other, x + y)
     __radd__ = __add__
 
     def __sub__(self, other):
         x = long(self)
-        y = long(other)
+        y = other      # may be a float
         return self._widen(other, x - y)
 
     def __rsub__(self, other):
         y = long(self)
-        x = long(other)
+        x = other      # may be a float
         return self._widen(other, x - y)
 
     def __mul__(self, other):
         x = long(self)
-        if not isinstance(other, (int, long)):
-            return x * other
-        y = long(other)
+        y = other      # may be a float
         return self._widen(other, x * y)
     __rmul__ = __mul__
 
     def __div__(self, other):
         x = long(self)
-        y = long(other)
-        return self._widen(other, x // y)
+        y = other      # may be a float
+        return self._widen(other, x / y)
 
     __floordiv__ = __div__
 
     def __rdiv__(self, other):
         y = long(self)
-        x = long(other)
-        return self._widen(other, x // y)
+        x = other      # may be a float
+        return self._widen(other, x / y)
 
     __rfloordiv__ = __rdiv__
 
     def __mod__(self, other):
         x = long(self)
-        y = long(other)
+        y = other      # not rpython if it is a float
         return self._widen(other, x % y)
 
     def __rmod__(self, other):
         y = long(self)
-        x = long(other)
+        x = other      # not rpython if it is a float
         return self._widen(other, x % y)
 
     def __divmod__(self, other):
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
@@ -602,3 +602,12 @@
 
         assert r_uint64(self._64_umax) + r_uint64(1) == r_uint64(0)
         assert r_uint64(0) - r_uint64(1) == r_uint64(self._64_umax)
+
+    def test_operation_with_float(self):
+        def f(x):
+            assert r_longlong(x) + 0.5 == 43.5
+            assert r_longlong(x) - 0.5 == 42.5
+            assert r_longlong(x) * 0.5 == 21.5
+            assert r_longlong(x) / 0.8 == 53.75
+        f(43)
+        interpret(f, [43])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to