From 2bebadfe517c8c3c5a24f246eb44b5fa9dfc2cf3 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Mon, 21 Jan 2008 21:54:47 +0000 Subject: [PATCH] Issue 1678380: fix a bug identifying -0.0 and 0.0 --- Lib/test/test_float.py | 21 +++++++++++++++++++++ Misc/NEWS | 3 +++ Python/compile.c | 15 ++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index fb47db8eb08..2f0d7840c8c 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -99,6 +99,27 @@ class IEEEFormatTestCase(unittest.TestCase): ('ob_type); + /* _and_ to distinguish 0.0 from -0.0 e.g. on IEEE platforms */ + if (PyFloat_Check(o)) { + double d = PyFloat_AS_DOUBLE(o); + unsigned char* p = (unsigned char*) &d; + /* all we need is to make the tuple different in either the 0.0 + * or -0.0 case from all others, just to avoid the "coercion". + */ + if (*p==0 && p[sizeof(double)-1]==0) + t = PyTuple_Pack(3, o, o->ob_type, Py_None); + else + t = PyTuple_Pack(2, o, o->ob_type); + } else { + t = PyTuple_Pack(2, o, o->ob_type); + } if (t == NULL) return -1;