From: Sean Anderson Date: Wed, 24 Nov 2021 18:26:13 +0000 (-0500) Subject: include/c: Add abs_diff macro X-Git-Tag: v2.38-rc1~118 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adc21ee18fb8af79adaf9d4254ab0f935e38f784;p=thirdparty%2Futil-linux.git include/c: Add abs_diff macro This macro calculates abs(a - b). It is especially useful for unsigned numbers. Signed-off-by: Sean Anderson --- diff --git a/include/c.h b/include/c.h index 354b59e299..ba799d8fd3 100644 --- a/include/c.h +++ b/include/c.h @@ -159,6 +159,14 @@ _max1 > _max2 ? _max1 : _max2; }) #endif +#ifndef abs_diff +# define abs_diff(x, y) __extension__ ({ \ + __typeof__(x) _a = (x); \ + __typeof__(y) _b = (y); \ + (void) (&_a == &_b); \ + _a > _b ? _a - _b : _b - _a; }) +#endif + #ifndef cmp_numbers # define cmp_numbers(x, y) __extension__ ({ \ __typeof__(x) _a = (x); \