]> git.ipfire.org Git - thirdparty/systemd.git/commit
tree-wide: Use our own macros instead of fabs()/fmax()/fmin()
authorDaan De Meyer <daan@amutable.com>
Fri, 15 May 2026 11:06:21 +0000 (11:06 +0000)
committerDaan De Meyer <daan@amutable.com>
Mon, 18 May 2026 21:17:38 +0000 (21:17 +0000)
commitb2bfe5b4748a804e7ea25a4925102412967a5e4e
tree9be7337eb272670b99ccc1775d87c6b7ab027258
parent7d2925fcde70ed221658e01ffb6f2797061d3520
tree-wide: Use our own macros instead of fabs()/fmax()/fmin()

To make this work, ABS() is made generic so it also works on
floats and doubles.

While at it, fold the __ABS_INTEGER indirection and the
assert_cc(sizeof(long long) == sizeof(intmax_t)) away. The previous
form switched between __builtin_llabs (clang) and __builtin_imaxabs
(gcc), with the assert keeping the two paths behaviorally identical
on every platform we build for. imaxabs was originally chosen because
intmax_t is conceptually the widest signed integer type the platform
exposes, but the _Generic ABS already casts to (long long) before the
call, so the extra width imaxabs could in theory carry was being
narrowed away immediately anyway. With both paths collapsed to
__builtin_llabs((long long) (a)), the size relationship between
long long and intmax_t is no longer relevant.

Also add explicit unsigned long long / unsigned long / unsigned int
cases that pass the argument through unchanged. The previous default
branch cast unsigned values to (long long); for values above LLONG_MAX
this reinterprets them as negative, and __builtin_llabs(LLONG_MIN) is
UB. Unsigned values are already non-negative, so passing them through
is both correct and avoids the narrowing. Smaller unsigned types
(unsigned char, unsigned short) still go through the default branch
but promote to int first and fit in long long losslessly.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
src/fundamental/macro-fundamental.h
src/libsystemd/sd-bus/test-bus-marshal.c
src/libsystemd/sd-json/test-json.c
src/shared/color-util.c
src/test/test-parse-util.c
src/test/test-random-util.c
src/timesync/timesyncd-manager.c