Author: Amaury Forgeot d'Arc <[email protected]>
Branch: decimal-libmpdec
Changeset: r73808:37fcab3a88c9
Date: 2014-09-30 10:52 +0200
http://bitbucket.org/pypy/pypy/changeset/37fcab3a88c9/

Log:    Fix comparison with complex

diff --git a/pypy/module/_decimal/interp_decimal.py 
b/pypy/module/_decimal/interp_decimal.py
--- a/pypy/module/_decimal/interp_decimal.py
+++ b/pypy/module/_decimal/interp_decimal.py
@@ -770,7 +770,8 @@
             new_status = (rmpdec.MPD_Float_operation |
                           rffi.cast(lltype.Signed, context.ctx.c_status))
             context.ctx.c_status = rffi.cast(rffi.UINT, new_status)
-            w_w = decimal_from_float(space, None, w_w, context, exact=True)
+            w_w = decimal_from_float(space, None, space.wrap(real),
+                                     context, exact=True)
         else:
             return space.w_NotImplemented, None, None
     elif space.isinstance_w(w_w, space.fromcache(State).w_Rational):
diff --git a/pypy/module/_decimal/test/test_decimal.py 
b/pypy/module/_decimal/test/test_decimal.py
--- a/pypy/module/_decimal/test/test_decimal.py
+++ b/pypy/module/_decimal/test/test_decimal.py
@@ -21,6 +21,12 @@
         cls.w_assertEqual = space.appexec([], """():
             def assertEqual(x, y): assert x == y
             return assertEqual""")
+        cls.w_assertIs = space.appexec([], """():
+            def assertIs(x, y): assert x is y
+            return assertIs""")
+        cls.w_assertNotEqual = space.appexec([], """():
+            def assertNotEqual(x, y): assert x != y
+            return assertNotEqual""")
         cls.w_assertRaises = space.appexec([], """(): return raises""")
 
     def test_explicit_empty(self):
@@ -888,6 +894,26 @@
             doit(c, signal=FloatOperation)
             test_containers(c, signal=FloatOperation)
 
+    def test_decimal_complex_comparison(self):
+        Decimal = self.decimal.Decimal
+
+        da = Decimal('0.25')
+        db = Decimal('3.0')
+        self.assertNotEqual(da, (1.5+0j))
+        self.assertNotEqual((1.5+0j), da)
+        self.assertEqual(da, (0.25+0j))
+        self.assertEqual((0.25+0j), da)
+        self.assertEqual((3.0+0j), db)
+        self.assertEqual(db, (3.0+0j))
+
+        self.assertNotEqual(db, (3.0+1j))
+        self.assertNotEqual((3.0+1j), db)
+
+        self.assertIs(db.__lt__(3.0+0j), NotImplemented)
+        self.assertIs(db.__le__(3.0+0j), NotImplemented)
+        self.assertIs(db.__gt__(3.0+0j), NotImplemented)
+        self.assertIs(db.__le__(3.0+0j), NotImplemented)
+
     def test_decimal_fraction_comparison(self):
         C = self.decimal
         D = self.decimal.Decimal
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to