[Python-checkins] r60741 - python/trunk/Lib/decimal.py python/trunk/Lib/numbers.py

raymond.hettinger python-checkins at python.org
Tue Feb 12 02:18:03 CET 2008


Author: raymond.hettinger
Date: Tue Feb 12 02:18:03 2008
New Revision: 60741

Modified:
   python/trunk/Lib/decimal.py
   python/trunk/Lib/numbers.py
Log:
Bring decimal a bit closer to the spec for Reals.

Modified: python/trunk/Lib/decimal.py
==============================================================================
--- python/trunk/Lib/decimal.py	(original)
+++ python/trunk/Lib/decimal.py	Tue Feb 12 02:18:03 2008
@@ -1519,6 +1519,20 @@
 
     __trunc__ = __int__
 
+    @property
+    def real(self):
+        return self
+
+    @property
+    def imag(self):
+        return Decimal(0)
+
+    def conjugate(self):
+        return self
+
+    def __complex__(self):
+        return complex(float(self))
+
     def __long__(self):
         """Converts to a long.
 

Modified: python/trunk/Lib/numbers.py
==============================================================================
--- python/trunk/Lib/numbers.py	(original)
+++ python/trunk/Lib/numbers.py	Tue Feb 12 02:18:03 2008
@@ -51,10 +51,7 @@
 
 ## Notes on Decimal and it how relates to the numeric tower
 ## --------------------------------------------------------
-## Decimal is Real except that it does not support the real and imag properties
-## or the conjugate() and complex() methods.  If those get defined at some
-## point, they cannot use the default implementation which would be sensitive
-## to decimal.Context and could produce different answers at different times.
+## Decimal is Real except that it does not support rich comparisons.
 ##
 ## Decimal has some of the characteristics of Integrals.  It provides
 ## logical operations but not as operators.  The logical operations only apply


More information about the Python-checkins mailing list