Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!ginosko!uunet!ncrlnk!cipc1!gmaranca From: gmaranca@cipc1.Dayton.NCR.COM (Gabriel Maranca) Newsgroups: comp.lang.c Subject: Type-independent absolute value Keywords: abs, labs Message-ID: <1389@cipc1.Dayton.NCR.COM> Date: 4 Oct 89 11:23:18 GMT 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 standard 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