Path: utzoo!attcan!uunet!wuarchive!ukma!gatech!hubcap!ncrcae!ncrlnk!cipc1!gmaranca
From: gmaranca@cipc1.Dayton.NCR.COM (Gabriel Maranca)
Newsgroups: comp.lang.c
Subject: ABS for longs and ints
Message-ID: <1381@cipc1.Dayton.NCR.COM>
Date: 29 Sep 89 21:23:21 GMT
References: abs, labs, macro, math.h
Reply-To: gmaranca@cipc1.Dayton.NCR.COM (Gabriel Maranca)
Organization: NCR Controller's Division - F*A*S*T - Dayton, OH
Lines: 21

Does anybody know why the abs math function is not type independent? Or has
this been changed in ANSI "C"?

I use the following macro instead of the library function:

#define ABS(x) (((long)(x) < 0L)? -(x) : (x))

This works for ints and longs, by casting the argument to a long for the
comparison, and then returning the absolute value of the argument with
its original type.

Is this non-ANSI or unportable? It works for me.

---
#Gabriel Maranca
#Gabriel.Maranca@cipc1.Dayton.NCR.COM
#...!uunet!ncrlnk!cipc1!gmaranca
-- 
#Gabriel Maranca
#Gabriel.Maranca@cipc1.Dayton.NCR.COM
#...!uunet!ncrlnk!cipc1!gmaranca