[Python-checkins] python/dist/src/Objects floatobject.c, 2.126,
2.127
mwh at users.sourceforge.net
mwh at users.sourceforge.net
Thu Feb 19 14:35:25 EST 2004
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3489/Objects
Modified Files:
floatobject.c
Log Message:
"Fix" (for certain configurations of the planets, including
recent gcc on Linux/x86)
[ 899109 ] 1==float('nan')
by implementing rich comparisons for floats.
Seems to make comparisons involving NaNs somewhat less surprising
when the underlying C compiler actually implements C99 semantics.
Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.126
retrieving revision 2.127
diff -C2 -d -r2.126 -r2.127
*** floatobject.c 17 Jan 2004 14:19:44 -0000 2.126
--- floatobject.c 19 Feb 2004 19:35:22 -0000 2.127
***************
*** 361,364 ****
--- 361,398 ----
}
+ static PyObject*
+ float_richcompare(PyObject *v, PyObject *w, int op)
+ {
+ double i, j;
+ int r = 0;
+
+ CONVERT_TO_DOUBLE(v, i);
+ CONVERT_TO_DOUBLE(w, j);
+
+ PyFPE_START_PROTECT("richcompare", return NULL)
+ switch (op) {
+ case Py_EQ:
+ r = i==j;
+ break;
+ case Py_NE:
+ r = i!=j;
+ break;
+ case Py_LE:
+ r = i<=j;
+ break;
+ case Py_GE:
+ r = i>=j;
+ break;
+ case Py_LT:
+ r = i<j;
+ break;
+ case Py_GT:
+ r = i>j;
+ break;
+ }
+ PyFPE_END_PROTECT(a)
+ return PyBool_FromLong(r);
+ }
+
static long
float_hash(PyFloatObject *v)
***************
*** 835,839 ****
0, /* tp_traverse */
0, /* tp_clear */
! 0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
--- 869,873 ----
0, /* tp_traverse */
0, /* tp_clear */
! (richcmpfunc)float_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
More information about the Python-checkins
mailing list