]> granicus.if.org Git - python/commitdiff
float_abs() again: Guido pointed out that this could screw up in the
authorTim Peters <tim.peters@gmail.com>
Thu, 1 Nov 2001 21:51:15 +0000 (21:51 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 1 Nov 2001 21:51:15 +0000 (21:51 +0000)
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.

Objects/floatobject.c

index 82aa963a88de747168f0c3c1854190d73cef6043..1efef4b02e22bd69d11ffb7221d3ce02872b542b 100644 (file)
@@ -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