fabs(x) vs. (x) < 0 ? -(x) : (x)

braner at batcomputer.UUCP braner at batcomputer.UUCP
Tue Feb 3 14:50:02 AEST 1987


[]

Somebody already said this a LONG time ago:  Any macro definition of
fabs() requires floating-point arithmetic (e.g. comparision with 0).
That is A LOT slower than a dedicated fabs() function, written in
assembly language of course, that simply clears the sign bit.

In this context I'd like to complain again about the fact that, for
historical reasons, the floating-point libraries provided with C compilers
are generally far inferior to those provided with, say, FORTRAN compilers.
Not very long ago most C compilers came without FP support at all, presumably
assuming that C was used for system programming only.  Even now most
microcomputer implementations (on the 68000 at least) seem to have many bugs
and are very slow.  Compare, say, Megamax C with Absoft FORTRAN (both on
the 68000).

Since many people are now turning to C for scientific programming, I hope
that compiler vendors are taking a second look at their ad-hoc second-thought
FP slap-ons.

THE COMPLETE FP LIBRARY MUST BE WRITTEN IN HAND-OPTIMIZED ASSEMBLER LANGUAGE!!!

- Moshe Braner



More information about the Comp.lang.c mailing list