Author: Lars Wassermann <[email protected]>
Branch: 
Changeset: r459:7c7a00b215d5
Date: 2013-06-17 16:01 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/7c7a00b215d5/

Log:    fixed error in quo primitive: round towards 0 instead of -inf

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -235,7 +235,11 @@
 def func(interp, s_frame, receiver, argument):
     if argument == 0:
         raise PrimitiveFailedError()
-    return interp.space.wrap_int(receiver // argument)
+    res = receiver // argument
+    # see 
http://python-history.blogspot.de/2010/08/why-pythons-integer-division-floors.html
+    if res < 0:
+        res = res + 1
+    return interp.space.wrap_int(res)
 
 # #bitShift: -- return the shifted value
 @expose_primitive(BIT_SHIFT, unwrap_spec=[object, int])
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -116,6 +116,7 @@
 def test_small_int_quo():
     assert prim(primitives.QUO, [12,3]).value == 4
     assert prim(primitives.QUO, [12,7]).value == 1
+    assert prim(primitives.QUO, [-9,4]).value == -2
 
 def test_small_int_quo_fail():
     prim_fails(primitives.QUO, [12, 0])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to