Path: utzoo!attcan!uunet!ginosko!uakari.primate.wisc.edu!uflorida!mailrus!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps From: flaps@dgp.toronto.edu (Alan J Rosenthal) Newsgroups: comp.lang.c Subject: Re: ABS for longs and ints Message-ID: <1989Sep30.140337.27752@jarvis.csri.toronto.edu> Date: 30 Sep 89 18:03:37 GMT References: <1381@cipc1.Dayton.NCR.COM> Lines: 19 gmaranca@cipc1.Dayton.NCR.COM (Gabriel Maranca) writes: >#define ABS(x) (((long)(x) < 0L)? -(x) : (x)) ... >Is this non-ANSI or unportable? It works for me. It is portable but will only work for ints and longs. But the following is portable and will work for all types, including unsigned long, double, and long long if it exists: #define ABS(x) (((x) < 0) ? -(x) : (x)) The zero will get promoted to the correct type. Like hey folks, C fully supports "mixed mode" arithmetic. It isn't fortran. ajr -- Vs encr vf n xvaq bs frk, gura n chapu va gur zbhgu vf n xvaq bs gnyxvat.