summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-09-23 19:22:41 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-09-23 19:22:41 (GMT)
commite1c69b3f6ff1f86fe5e94a41a877aa08541b62f0 (patch)
tree25370a9e2bbe09d0b750d147c3d4a270a7acb2d5 /Objects
parent862f0593d8e8c7cd510b598296c73b25168d0472 (diff)
downloadcpython-e1c69b3f6ff1f86fe5e94a41a877aa08541b62f0.zip
cpython-e1c69b3f6ff1f86fe5e94a41a877aa08541b62f0.tar.gz
cpython-e1c69b3f6ff1f86fe5e94a41a877aa08541b62f0.tar.bz2
float_richcompare(): Use the new Py_IS_NAN macro to ensure that, on
platforms where that macro works, NaN compared to an int or long works the same as NaN compared to a finite float.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 46c05b2..539c4a9 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -384,13 +384,11 @@ float_richcompare(PyObject *v, PyObject *w, int op)
if (PyFloat_Check(w))
j = PyFloat_AS_DOUBLE(w);
- else if (Py_IS_INFINITY(i)) {
- /* XXX If we had a reliable way to check whether i is a
- * XXX NaN, it would belong in this branch too.
- */
+ else if (Py_IS_INFINITY(i) || Py_IS_NAN(i)) {
if (PyInt_Check(w) || PyLong_Check(w))
- /* The magnitude of i exceeds any finite integer,
- * so it doesn't matter which int we compare i with.
+ /* If i is an infinity, its magnitude exceeds any
+ * finite integer, so it doesn't matter which int we
+ * compare i with. If i is a NaN, similarly.
*/
j = 0.0;
else
@@ -403,7 +401,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
* Cray single with 48 bits of precision, and long has 64
* bits.
*/
-#if SIZEOF_LONG > 4
+#if SIZEOF_LONG > 6
unsigned long abs = (unsigned long)(jj < 0 ? -jj : jj);
if (abs >> 48) {
/* Needs more than 48 bits. Make it take the
@@ -443,10 +441,10 @@ float_richcompare(PyObject *v, PyObject *w, int op)
nbits = _PyLong_NumBits(w);
if (nbits == (size_t)-1 && PyErr_Occurred()) {
/* This long is so large that size_t isn't big enough
- * to hold the # of Python digits. Replace with
- * little doubles that give the same outcome --
- * w is so large that its magnitude must exceed
- * the magnitude of any finite float.
+ * to hold the # of bits. Replace with little doubles
+ * that give the same outcome -- w is so large that
+ * its magnitude must exceed the magnitude of any
+ * finite float.
*/
PyErr_Clear();
i = (double)vsign;