]> granicus.if.org Git - python/commitdiff
Bring decimal a bit closer to the spec for Reals.
authorRaymond Hettinger <python@rcn.com>
Tue, 12 Feb 2008 01:18:03 +0000 (01:18 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 12 Feb 2008 01:18:03 +0000 (01:18 +0000)
Lib/decimal.py
Lib/numbers.py

index 4f23d33d0de2eb66c25b55b98133e2e6fbe84ccf..dbe06951078f816a181fc3d2273c7340f5a6e6c2 100644 (file)
@@ -1519,6 +1519,20 @@ class Decimal(object):
 
     __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.
 
index eed1f42c25ffbec3b050c1cec41e0c5f8aa6ff6a..b8a5c36db941efd7808f6bd8903fb062975d3948 100644 (file)
@@ -51,10 +51,7 @@ Inexact.register(float)
 
 ## 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