Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!sri-spam!mordor!styx!twg-ap!amdahl!pyramid!prls!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP Newsgroups: comp.lang.c Subject: Re: fabs(x) vs. (x) < 0 ? -(x) : (x) Message-ID: <645@mcgill-vision.UUCP> Date: Wed, 11-Feb-87 02:02:48 EST Article-I.D.: mcgill-v.645 Posted: Wed Feb 11 02:02:48 1987 Date-Received: Fri, 13-Feb-87 06:24:10 EST References: <4943@mimsy.UUCP> <2550005@hpisod2.HP> <756@unc.unc.UUCP> <1315@ho95e.ATT.COM> Distribution: na Organization: McGill University, Montreal Lines: 54 In article <1315@ho95e.ATT.COM>, wcs@ho95e.ATT.COM (#Bill.Stewart) writes: > 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). > #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. I would be very surprised to find the SVR2 (ho95e *is* SVR2 on a 3B20, isn't it?) C compiler that badly broken. Or maybe you just posted without bothering to test? Anyway.... % cat -n x.c 1 #define foo(x) ((x) & 0xffff7fff) 2 3 main() 4 { 5 float f; 6 7 f = -12.34; 8 f = foo(f); 9 printf("f = %g\n",f); 10 } % cc x.c "x.c", line 8: operands of & have incompatible types % >> 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. I would really like a C compiler that produces anything that could *touch* the "Kahan's magic square root" code of the 4.3 VAX libm. Or the generation of exceptions in the correct manner, which usually requires code the compiler simply can't generate. You wind up writing it in assembly and putting it in a C file full of asm()s, which is an exercise in stupidity. I tend to agree with braner. Or is your definition of an "adequate" compiler one which can recognize "oh, this code is trying to do a square root, so let's plug in the good square root code"? I think you will find there aren't any such. der Mouse USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse think!mosart!mcgill-vision!mouse Europe: mcvax!decvax!utcsri!mcgill-vision!mouse ARPAnet: think!mosart!mcgill-vision!mouse@harvard.harvard.edu