Author: stian
Branch: bigint-with-int
Changeset: r65993:0cbc8eed974c
Date: 2013-08-06 20:30 +0200
http://bitbucket.org/pypy/pypy/changeset/0cbc8eed974c/
Log: Fix for LONG * -INT
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -81,6 +81,8 @@
return rffi.cast(LONG_TYPE, x)
def _store_digit(x):
+ # TMP
+ assert x >= 0
return rffi.cast(STORE_TYPE, x)
_store_digit._annspecialcase_ = 'specialize:argtype(0)'
@@ -717,13 +719,15 @@
if b == MIN_VALUE:
# Fallback to long.
return self.mul(rbigint.fromint(b))
-
- digit = _widen_digit(b)
+ elif self.sign == 0 or b == 0:
+ return NULLRBIGINT
+
+
+ digit = _widen_digit(abs(b))
+
+ assert digit > 0
asize = self.numdigits()
- if self.sign == 0 or b == 0:
- return NULLRBIGINT
-
if asize == 1:
if self._digits[0] == NULLDIGIT:
return NULLRBIGINT
@@ -2036,6 +2040,7 @@
# XXX: Temp
if b.sign != 0 and b.numdigits() == 1 and b.digit(0) == 0:
print "VERY BAD!"
+ raise ZeroDivisionError("long division or modulo by zero")
if (size_a < size_b or
(size_a == size_b and
diff --git a/rpython/rlib/test/test_rbigint.py
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -332,6 +332,13 @@
result = f1.int_mul(y)
assert result.tolong() == x * y
+ def test_int_mul_bug1(self):
+ x = 89731783189318938713891893879123L
+ y = -1
+ f1 = rbigint.fromlong(x)
+ result = f1.int_mul(y)
+ assert result.tolong() == x * y
+
def test_tofloat(self):
x = 12345678901234567890L ** 10
f1 = rbigint.fromlong(x)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit