Index: Python/ast.c =================================================================== --- Python/ast.c (revision 54277) +++ Python/ast.c (working copy) @@ -1530,7 +1530,7 @@ constant. The peephole optimizer already does something like this but it doesn't handle the case where the constant is (sys.maxint - 1). In that case, we want a PyIntObject, not a - PyLongObject. + PyLongObject. However, preserve the sign of -0.0. */ if (TYPE(CHILD(n, 0)) == MINUS && NCH(n) == 2 @@ -1540,14 +1540,22 @@ && NCH(ppower) == 1 && TYPE((patom = CHILD(ppower, 0))) == atom && TYPE((pnum = CHILD(patom, 0))) == NUMBER) { - char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2); - if (s == NULL) - return NULL; - s[0] = '-'; - strcpy(s + 1, STR(pnum)); - PyObject_FREE(STR(pnum)); - STR(pnum) = s; - return ast_for_atom(c, patom); + PyObject* thenum = parsenumber(STR(pnum)); + if (thenum == NULL) + return NULL; + if (!PyFloat_Check(thenum) || PyObject_IsTrue(thenum)) { + char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2); + if (s == NULL) + return NULL; + s[0] = '-'; + strcpy(s + 1, STR(pnum)); + PyObject_FREE(STR(pnum)); + STR(pnum) = s; + Py_DECREF(thenum); + return ast_for_atom(c, patom); + } else { + Py_DECREF(thenum); + } } expression = ast_for_expr(c, CHILD(n, 1)); Index: Lib/test/test_float.py =================================================================== --- Lib/test/test_float.py (revision 54277) +++ Lib/test/test_float.py (working copy) @@ -81,6 +81,7 @@ # on an IEEE platform, all we guarantee is that bit patterns # representing infinities or NaNs do not raise an exception; all else # is accident (today). +# let's also try to guarantee that -0.0 and 0.0 don't get confused. class IEEEFormatTestCase(unittest.TestCase): if float.__getformat__("double").startswith("IEEE"): @@ -99,7 +100,21 @@ ('