[pypy-svn] r5629 - in pypy/trunk/src/pypy/objspace/std: . test

mwh at codespeak.net mwh at codespeak.net
Fri Jul 23 12:39:48 CEST 2004


Author: mwh
Date: Fri Jul 23 12:39:48 2004
New Revision: 5629

Modified:
   pypy/trunk/src/pypy/objspace/std/intobject.py
   pypy/trunk/src/pypy/objspace/std/longobject.py
   pypy/trunk/src/pypy/objspace/std/test/test_intobject.py
Log:
paper over int**(negative int) shaped holes.


Modified: pypy/trunk/src/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/intobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/intobject.py	Fri Jul 23 12:39:48 2004
@@ -224,6 +224,9 @@
             raise OperationError(space.w_TypeError,
                              space.wrap("pow() 2nd argument "
                  "cannot be negative when 3rd argument specified"))
+        return space.pow(space.float(space.wrap(iv)),
+                         space.float(space.wrap(iw)),
+                         space.w_None)
         ## bounce it, since it always returns float
         raise FailedToImplement(space.w_ValueError,
                                 space.wrap("integer exponentiation"))
@@ -250,7 +253,7 @@
     except OverflowError:
         raise FailedToImplement(space.w_OverflowError,
                                 space.wrap("integer exponentiation"))
-    return ix
+    return W_IntObject(space, ix)
 
 """
 def pow__Int_Int_Int(space, w_int1, w_int2, w_int3):
@@ -265,14 +268,12 @@
     x = w_int1.intval
     y = w_int2.intval
     z = w_int3.intval
-    ret = _impl_int_int_pow(space, x, y, z)
-    return W_IntObject(space, ret)
+    return _impl_int_int_pow(space, x, y, z)
 
 def pow__Int_Int_None(space, w_int1, w_int2, w_int3):
     x = w_int1.intval
     y = w_int2.intval
-    ret = _impl_int_int_pow(space, x, y)
-    return W_IntObject(space, ret)
+    return _impl_int_int_pow(space, x, y)
 
 def neg__Int(space, w_int1):
     a = w_int1.intval

Modified: pypy/trunk/src/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/longobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/longobject.py	Fri Jul 23 12:39:48 2004
@@ -17,7 +17,6 @@
         assert isinstance(longval, long)
         w_self.longval = longval
 
-
 registerimplementation(W_LongObject)
 
 # int-to-long delegation
@@ -38,6 +37,11 @@
 delegate__Long.priority = PRIORITY_CHANGE_TYPE
 delegate__Long.can_fail = True
 
+## # long-to-float delegation
+## def delegate__Long(space, w_longobj):
+##     return W_FloatObject(space, float(w_longobj.longval))
+## delegate__Long.result_class = W_FloatObject
+## delegate__Long.priority = PRIORITY_CHANGE_TYPE
 
 # long__Long is supposed to do nothing, unless it has
 # a derived long object, where it should return
@@ -145,6 +149,10 @@
 def pow__Long_Long_None(space, w_long1, w_long2, w_none3):
     x = w_long1.longval
     y = w_long2.longval
+    if y < 0:
+        return space.pow(space.float(w_long1),
+                         space.float(w_long2),
+                         space.w_None)        
     z = x ** y
     return W_LongObject(space, z)
 

Modified: pypy/trunk/src/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_intobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_intobject.py	Fri Jul 23 12:39:48 2004
@@ -170,9 +170,6 @@
         f1, f2 = [iobj.W_IntObject(self.space, i) for i in (10, 20)]
         self.assertEquals(self.space.w_OverflowError,
                           self._unwrap_nonimpl(iobj.pow__Int_Int_None, self.space, f1, f2, self.space.w_None))
-        f1, f2 = [iobj.W_IntObject(self.space, i) for i in (10, -1)]
-        self.assertEquals(self.space.w_ValueError,
-                          self._unwrap_nonimpl(iobj.pow__Int_Int_None, self.space, f1, f2, self.space.w_None))
 
     def test_neg(self):
         x = 42
@@ -322,5 +319,8 @@
         n = sys.maxint + 1
         self.assert_(isinstance(n, long))
 
+    def test_pow(self):
+        self.assertEquals(pow(2, -10), 1/1024.)
+
 if __name__ == '__main__':
     testit.main()



More information about the Pypy-commit mailing list