Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Help with function Message-ID: <15697@haddock.ima.isc.com> Date: 19 Jan 90 20:17:50 GMT References: <2385@ektools.UUCP> <3477@cbnewsj.ATT.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Distribution: na Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 15 In article <3477@cbnewsj.ATT.COM> veenu@cbnewsj.ATT.COM (veenu.r.rashid,mt,) writes: >As it turns out, the abs() macro definition tends to return int, (but not >always!), while fabs() returns the correct floating point value. Now, is >this just a macro characteristic or is it the compiler I'm using. |abs| is a standard library function that expects an |int| and returns an |int|. I don't know anything about the macro definition on your machine, and neither should you, if you're interested in writing portable programs. Passing it a non-|int| value is undefined behavior; all bets are off. Karl W. Z. Heuer (karl@haddock.isc.com or ima!haddock!karl), The Walking Lint ________ I'm assuming you have a sane implementation. If |abs| is defined as #define abs(x) ((x) < 0 ? -(x) : (x)) then you should file a bug report, since it will break code like |abs(*p++)|.