[Python-Dev] math.fabs redundant?

Tim Peters tim.peters at gmail.com
Fri Jul 29 17:57:06 CEST 2005


[Skip]
> Why does math have an fabs function?  Both it and the abs builtin function
> wind up calling fabs() for floats.  abs() is faster to boot.

Nothing deep -- the math module supplies everything in C89's standard
libm (+ a few extensions), fabs() is a std C89 libm function.

There isn't a clear (to me) reason why one would be faster than the
other; sounds accidental; math.fabs() could certainly be made faster
(as currently implemented (via math_1), it endures a pile of
general-purpose "try to guess whether libm should have set errno"
boilerplate that's wasted (there are no domain or range errors
possible for fabs())).


More information about the Python-Dev mailing list