[pypy-svn] r10567 - in pypy/dist/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Apr 13 01:02:22 CEST 2005


Author: cfbolz
Date: Wed Apr 13 01:02:22 2005
New Revision: 10567

Modified:
   pypy/dist/pypy/objspace/std/longobject.py
   pypy/dist/pypy/objspace/std/test/test_longobject.py
Log:
More bugfixes for the long implementation.

Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py	(original)
+++ pypy/dist/pypy/objspace/std/longobject.py	Wed Apr 13 01:02:22 2005
@@ -44,6 +44,8 @@
         while i != 0 and self.digits[i] == 0:
             self.digits.pop(-1)
             i -= 1
+        if len(self.digits) == 1 and self.digits[0] == 0:
+            self.sign = 0
 
     def _getshort(self, index):
         a = self.digits[index // 2]
@@ -115,7 +117,8 @@
             return space.newint(int(w_value.digits[0]) * w_value.sign)
         elif w_value.sign == -1 and w_value.digits[0] & NONSIGN_MASK == 0:
             return space.newint(intmask(w_value.digits[0]))
-    return w_value   # 9999999999999L.__int__() == 9999999999999L
+    #subtypes of long are converted to long!
+    return long__Long(space, w_value)
 
 def float__Long(space, w_longobj): #YYYYYY
     try:
@@ -134,7 +137,7 @@
         elif w_value.sign == -1 and w_value.digits[0] & NONSIGN_MASK == 0:
             return intmask(w_value.digits[0])
     raise OperationError(space.w_OverflowError,
-                         space.wrap("long int too large to convert to int"))        
+                         space.wrap("long int too large to convert to int"))           
 
 def repr__Long(space, w_long): #YYYYYY
     return space.wrap(repr(w_long.longval()))
@@ -162,9 +165,15 @@
     ld1 = len(w_long1.digits)
     ld2 = len(w_long2.digits)
     if ld1 > ld2:
-        return space.newbool(False)
+        if w_long2.sign > 0:
+            return space.newbool(False)
+        else:
+            return space.newbool(True)
     elif ld1 < ld2:
-        return space.newbool(True)
+        if w_long2.sign > 0:
+            return space.newbool(True)
+        else:
+            return space.newbool(False)
     i = ld1 - 1
     while i >= 0:
         d1 = w_long1.digits[i]
@@ -285,6 +294,8 @@
                                     space.wrap("pow() 3rd argument cannot be 0"))
     result = W_LongObject(space, [r_uint(1)], 1)
     if lw.sign == 0:
+        if lz is not None:
+            result = mod__Long_Long(space, result, lz)
         return result
     if lz is not None:
         temp = mod__Long_Long(space, lv, lz)

Modified: pypy/dist/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_longobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_longobject.py	Wed Apr 13 01:02:22 2005
@@ -95,6 +95,7 @@
             space.raises_w(space.w_OverflowError, lobj.int_w__Long, space, w_lv)
             assert space.is_true(space.isinstance(lobj.int__Long(space, w_lv), space.w_long))
 
+
     def test_pow_lll(self):
         x = 10L
         y = 2L
@@ -123,6 +124,13 @@
         v = lobj.pow__Long_Long_None(self.space, f1, f2, self.space.w_None)
         assert v.longval() == x ** y
 
+    def test_normalize(self):
+        f1 = lobj.W_LongObject(self.space, [lobj.r_uint(1), lobj.r_uint(0)], 1)
+        f1._normalize()
+        assert len(f1.digits) == 1
+        f0 = lobj.W_LongObject(self.space, [lobj.r_uint(0)], 0)
+        assert self.space.is_true(
+            self.space.eq(lobj.sub__Long_Long(self.space, f1, f1), f0))
 
 class AppTestLong:
     def test_add(self):
@@ -136,4 +144,12 @@
     def test_mul(self):
         assert 363L * 2 ** 40 == 363L << 40
 
-    
+    def test_conversion(self):
+        class long2(long):
+            pass
+        x = long2(1L<<100)
+        y = int(x)
+        assert type(y) == long
+
+    def test_pow(self):
+        assert pow(0L, 0L, 1L) == 0L



More information about the Pypy-commit mailing list