Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!pt.cs.cmu.edu!sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: comp.lang.c Subject: Re: fabs(x) vs. (x) < 0 ? -(x) : (x) Message-ID: <512@aw.sei.cmu.edu.sei.cmu.edu> Date: Wed, 7-Jan-87 15:50:40 EST Article-I.D.: aw.512 Posted: Wed Jan 7 15:50:40 1987 Date-Received: Wed, 7-Jan-87 23:43:58 EST References: <2197@brl-adm.ARPA> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu.UUCP (PUT YOUR NAME HERE) Organization: Carnegie-Mellon University, SEI, Pgh, Pa Lines: 23 In article <2197@brl-adm.ARPA> rgenter@j.bbn.com (Rick Genter) writes: >On machines which do not support floating-point instructions, >libraries which implement the DEC G-format floating point (I think >that's right) format can implement fabs() much more efficiently as a >subroutine than as a macro. ... >whereas the routine fabs() could be: > >fabs: > bitclr x,#BIT_HIGH > return > >Obviously optimizations can be made depending on the intelligence of >your compiler, whether registers (or register-pairs) can hold floating >point values, etc. Still, it would be hard to beat a single bit-clear >(or AND) operation. If you really are implementing the VAX G data type, you must first check whether X is a reserved operand. That's another couple of instructions. By the way, you should clear not the high bit of X but the high bit of the low-order longword.