Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbatt!ihnp4!houxm!ho95e!wcs From: wcs@ho95e.UUCP Newsgroups: comp.lang.c Subject: Re: fabs(x) vs. (x) < 0 ? -(x) : (x) Message-ID: <1315@ho95e.ATT.COM> Date: Thu, 5-Feb-87 21:50:25 EST Article-I.D.: ho95e.1315 Posted: Thu Feb 5 21:50:25 1987 Date-Received: Sat, 7-Feb-87 18:26:45 EST References: <4943@mimsy.UUCP> <2550005@hpisod2.HP> <756@unc.unc.UUCP> <2181@batcomputer.tn.cornell.edu> Reply-To: wcs@ho95e.UUCP (46133-#Bill.Stewart,2G202,x0705,) Distribution: na Organization: AT&T Bell Labs 46133, Holmdel, NJ Lines: 24 In article <2181@batcomputer.tn.cornell.edu> braner@batcomputer.UUCP (braner) writes: >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. #define fabs(x) ( (x) & 0x7FFF ) is probably a *lot* faster than your assembly language function, since it doesn't need a function call. You'll have to #ifdef it to get the right bit pattern for your machine, and worry about details for double and double-extended versions, but for no-more-bits-than-a-long floating point it's ok. >[various complaints about most C compilers' FP code quality] Yeah, a lot of it's not exciting. The standard complaint is that everything is really done in double precision, when you can often get by with single. I suspect the 80*8* world is heading back in the PDP-11 direction though, since the 8087 gives you fairly wide arithmetic. >THE COMPLETE FP LIBRARY MUST BE WRITTEN IN HAND-OPTIMIZED ASSEMBLER LANGUAGE!!! Only if your compilers are inadequate for your machines, though some hand-tuning helps. -- # Bill Stewart, AT&T Bell Labs 2G-202, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs