When calculating the absolute value of an integer or a floating point value, is there any advantage of using abs from stdlib.h or fabs from math.h compared to using the conditional operator?
#define ABS(x) (((x) >= 0)? (x): -(x))
Code should use
int (or narrower),
fabs() with double,
long, etc. @Joachim Pileborg
Advantage: non-macro. Sequence point definitiveness. @EOF
-0.0 with OP's
0.0. if following IEC 60559 floating-point arithmetic.
ABS(0.0/0.0) attempts to change the sign. (Corner case concern).
fabs() are standard functions, readily understood by reviewers.
ABS() is not.
Performance: Profile to find what is best on your platform. What is best (speed, code size, memory size) varies by compiler.
No type checking with
Cannot take the address of the macro.