[Jython-checkins] jython: Distinguish constants 0j and -0j when generating code.

jeff.allen jython-checkins at python.org
Wed Dec 31 02:41:07 CET 2014


https://hg.python.org/jython/rev/43b491fcfe98
changeset:   7484:43b491fcfe98
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Sat Dec 20 23:51:33 2014 +0000
summary:
  Distinguish constants 0j and -0j when generating code.

Fixes a failure in test_complex: -0.0 and 0.0 are not the same constant.

files:
  Lib/test/test_complex.py            |   2 --
  src/org/python/compiler/Module.java |  16 ++++++++--------
  2 files changed, 8 insertions(+), 10 deletions(-)


diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -501,8 +501,6 @@
         self.assertEqual(complex(INF, 0).__getnewargs__(), (INF, 0.0))
 
     if float.__getformat__("double").startswith("IEEE"):
-        @unittest.skipIf(test_support.is_jython,
-                         "FIXME: not working in Jython")
         def test_plus_minus_0j(self):
             # test that -0j and 0j literals are not identified
             z1, z2 = 0j, -0j
diff --git a/src/org/python/compiler/Module.java b/src/org/python/compiler/Module.java
--- a/src/org/python/compiler/Module.java
+++ b/src/org/python/compiler/Module.java
@@ -101,14 +101,12 @@
     @Override
     public boolean equals(Object o) {
         if (o instanceof PyFloatConstant) {
-            double oVal = ((PyFloatConstant)o).value;
-            if (ZERO == value) {
-                // math.copysign() needs to distinguish signs of zeroes
-                return oVal == value && Double.toString(oVal).equals(Double.toString(value));
-            }
-            return oVal == value;
+            // Ensure hashtable works things like for -0.0 and NaN (see java.lang.Double.equals).
+            PyFloatConstant pyco = (PyFloatConstant)o;
+            return Double.doubleToLongBits(pyco.value) == Double.doubleToLongBits(value);
+        } else {
+            return false;
         }
-        return false;
     }
 }
 
@@ -138,7 +136,9 @@
     @Override
     public boolean equals(Object o) {
         if (o instanceof PyComplexConstant) {
-            return ((PyComplexConstant)o).value == value;
+            // Ensure hashtable works things like for -0.0 and NaN (see java.lang.Double.equals).
+            PyComplexConstant pyco = (PyComplexConstant)o;
+            return Double.doubleToLongBits(pyco.value) == Double.doubleToLongBits(value);
         } else {
             return false;
         }

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list