fabs(x) vs. (x) < 0 ? -(x) : (x)

Karl Heuer karl at haddock.UUCP
Fri Jan 9 18:46:26 AEST 1987


In article <4477 at ut-ngp.UUCP> jjr at ngp.UUCP (Jeff Rodriguez) writes:
>Why isn't fabs() implemented as a macro [ (X) < 0 ? -(X) : (X) ]?

I think it's primarily because of things like "y = fabs(sin(x))", which would
be inefficent, and "y = fabs(*px++)", which would be wrong.

Generally, the standard library functions are not implemented as macros unless
they evaluate each argument exactly once.  (There are exceptions, though.)

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list