summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2004-02-19 19:35:22 (GMT)
committerMichael W. Hudson <mwh@python.net>2004-02-19 19:35:22 (GMT)
commitd3b33b5f6f6f1b09c1ec7832329c8307edcb82cf (patch)
tree4c5d78f77d1f89ed0441f526a52c749169665cf5 /Objects
parentbbca8da3ca5191d68c4cd8777b8ba8632c0cff44 (diff)
downloadcpython-d3b33b5f6f6f1b09c1ec7832329c8307edcb82cf.zip
cpython-d3b33b5f6f6f1b09c1ec7832329c8307edcb82cf.tar.gz
cpython-d3b33b5f6f6f1b09c1ec7832329c8307edcb82cf.tar.bz2
"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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 7476ac7..3f06b4c 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -360,6 +360,40 @@ float_compare(PyFloatObject *v, PyFloatObject *w)
return (i < j) ? -1 : (i > j) ? 1 : 0;
}
+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)
{
@@ -834,7 +868,7 @@ PyTypeObject PyFloat_Type = {
float_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
- 0, /* tp_richcompare */
+ (richcmpfunc)float_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */