Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!crdgw1!crdos1!davidsen From: davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: Type-independent absolute value Keywords: abs, labs Message-ID: <799@crdos1.crd.ge.COM> Date: 4 Oct 89 18:18:45 GMT References: <1389@cipc1.Dayton.NCR.COM> Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: GE Corp R&D Center Lines: 20 In article <1389@cipc1.Dayton.NCR.COM>, gmaranca@cipc1.Dayton.NCR.COM (Gabriel Maranca) writes: | [ she uses... ] | #define ABS(x) (((long)(x) < 0L)? -(x) : (x)) | [ and asks... ] | Is this non-ANSI or unportable? It works for me. I don't see anything which is non-portable code, but have a few suggestions: 1. instead of -(x) use (-(x)). 2. you might want to use (double) to work with more types 3. you still have to be careful about what you use for an argument to avoid things like ABS(x[m++]) which are only evaluated once if ABS is a procedure. -- bill davidsen (davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen) "The world is filled with fools. They blindly follow their so-called 'reason' in the face of the church and common sense. Any fool can see that the world is flat!" - anon