[th/minmax] improve NM_MIN()/NM_MAX() macros and use them everywhere
I think glib's MIN()
/MAX()
macros should not be used. Instead, our variant should be used because:
- it evaluates arguments exactly once (make it more function like, and behave correctly when arguments have side effects).
- has a compile time assert that arguments have the same signedness.
Previously, NM_MIN()
/NM_MAX()
could not be used in a static context. That is fixed by this branch using __builtin_choose_expr()
.
-- except, there are a very few places where NM_MIN()
/NM_MAX()
still doesn't work. In those places, use NM_MIN_CONST()
/NM_MAX_CONST()
instead, which has static assertions that the arguments are compile time constants and have the same signedness.
Improve those macros and use NM_MIN()/NM_MAX() instead of MIN()
/MAX()
.