From: Tim Peters Date: Thu, 1 Nov 2001 21:51:15 +0000 (+0000) Subject: float_abs() again: Guido pointed out that this could screw up in the X-Git-Tag: v2.2.1c1~917 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=faf0cd21edde392d4d30e2e4f7d9fa2fb9973b71;p=python float_abs() again: Guido pointed out that this could screw up in the presence of NaNs. So pass the issue on to the platform libm fabs(); after all, fabs() is a std C function because you can't implement it correctly in portable C89. --- diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 82aa963a88..1efef4b02e 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -568,12 +568,7 @@ float_pos(PyFloatObject *v) static PyObject * float_abs(PyFloatObject *v) { - if (v->ob_fval < 0) - return float_neg(v); - else if (v->ob_fval > 0) - return float_pos(v); - else /* ensure abs(-0) is +0 */ - return PyFloat_FromDouble(+0.0); + return PyFloat_FromDouble(fabs(v->ob_fval)); } static int