[pypy-svn] r5597 - pypy/trunk/src/pypy/module

mwh at codespeak.net mwh at codespeak.net
Wed Jul 21 13:05:36 CEST 2004


Author: mwh
Date: Wed Jul 21 13:05:36 2004
New Revision: 5597

Modified:
   pypy/trunk/src/pypy/module/__builtin__module.py
Log:
make complex.__description somewhat less insane.
add __radd__ (probably should add the other rop's too, but parrotbench
doesn't seem to excercise them).


Modified: pypy/trunk/src/pypy/module/__builtin__module.py
==============================================================================
--- pypy/trunk/src/pypy/module/__builtin__module.py	(original)
+++ pypy/trunk/src/pypy/module/__builtin__module.py	Wed Jul 21 13:05:36 2004
@@ -610,8 +610,8 @@
 
     Create a complex number from a real part and an optional imaginary part.
     This is equivalent to (real + imag*1j) where imag defaults to 0."""
-    PREC_REPR = 0 # 17
-    PREC_STR = 0 # 12
+    PREC_REPR = 17
+    PREC_STR = 12
     
     def __init__(self, real=0.0, imag=None):
         if isinstance(real, str) and imag is not None:
@@ -651,16 +651,10 @@
 
 
     def __description(self, precision):
-        sign = '+'
-        if self.imag < 0.:
-            sign = ''
         if self.real != 0.:
-            format = "(%%%02dg%%s%%%02dgj)" % (precision, precision)
-            args = (self.real, sign, self.imag)
+            return "(%.*g%+.*gj)"%(precision, self.real, precision, self.imag)
         else:
-            format = "%%%02dgj" % precision
-            args = self.imag
-        return format % args
+            return "%.*gj"%(precision, self.imag)
 
 
     def __repr__(self):
@@ -953,6 +947,9 @@
         return self / other
     
 
+    def __radd__(self, other):
+        return self + other
+
 #    def __new__(self, ...):
 #        pass
 



More information about the Pypy-commit mailing list