abs Function (Macro)

math.h, stdlib.h, timath.h

#define abs(x) ({typeof(x) __x = (x); __x >= 0 ? __x : -__x;})

Absolute value of a number.

abs returns the absolute value of a numeric argument x, which may be either an integer or a floating point value. The returned value is of the same type as the argument.

Note: abs is a smart macro compiling to open code which depends on the type of the argument.


See also: labs, fabs