[pypy-svn] r10466 - in pypy/dist/pypy/tool: . test
pedronis at codespeak.net
pedronis at codespeak.net
Fri Apr 8 21:09:32 CEST 2005
Author: pedronis
Date: Fri Apr 8 21:09:32 2005
New Revision: 10466
Modified:
pypy/dist/pypy/tool/rarithmetic.py
pypy/dist/pypy/tool/test/test_rarithmetic.py
Log:
make int(r_uint()) intmask(r_uint()) do the right thing
Modified: pypy/dist/pypy/tool/rarithmetic.py
==============================================================================
--- pypy/dist/pypy/tool/rarithmetic.py (original)
+++ pypy/dist/pypy/tool/rarithmetic.py Fri Apr 8 21:09:32 2005
@@ -157,6 +157,8 @@
def intmask(n):
if isinstance(n, int):
return n
+ if isinstance(n, r_uint):
+ n = long(n)
n &= LONG_MASK
if n >= LONG_TEST:
n -= 2*LONG_TEST
@@ -181,6 +183,12 @@
def __new__(klass, val):
return long.__new__(klass, val & klass._mask)
+ def __int__(self):
+ if self < LONG_TEST:
+ return int(self)
+ else:
+ return intmask(self)
+
def __add__(self, other):
x = long(self)
y = long(other)
Modified: pypy/dist/pypy/tool/test/test_rarithmetic.py
==============================================================================
--- pypy/dist/pypy/tool/test/test_rarithmetic.py (original)
+++ pypy/dist/pypy/tool/test/test_rarithmetic.py Fri Apr 8 21:09:32 2005
@@ -115,6 +115,9 @@
# pow is buggy, dowsn't allow our type
#self.binary_test(lambda x, y: pow(x, y, 42), (2, 3, 5, 1000))
+ def test_back_to_int(self):
+ assert int(r_uint(-1)) == -1
+
def unary_test(self, f):
for arg in (0, 3, 12345):
res = f(arg) & maxint_mask
@@ -149,6 +152,7 @@
assert intmask(1 << (machbits-1)) == 1 << (machbits-1)
assert intmask(sys.maxint+1) == minint
assert intmask(minint-1) == sys.maxint
+ assert intmask(r_uint(-1)) == -1
def test_ovfcheck():
More information about the Pypy-commit
mailing list