1 /* CC0 (Public domain) - see LICENSE file for details */
7 #include <ccan/build_assert/build_assert.h>
9 #if !HAVE_STATEMENT_EXPR || !HAVE_TYPEOF
11 * Without these, there's no way to avoid unsafe double evaluation of
14 #error Sorry, minmax module requires statement expressions and typeof
17 #if HAVE_BUILTIN_TYPES_COMPATIBLE_P
18 #define MINMAX_ASSERT_COMPATIBLE(a, b) \
19 BUILD_ASSERT(__builtin_types_compatible_p(a, b))
21 #define MINMAX_ASSERT_COMPATIBLE(a, b) \
29 MINMAX_ASSERT_COMPATIBLE(typeof(_a), typeof(_b)); \
37 MINMAX_ASSERT_COMPATIBLE(typeof(_a), typeof(_b)); \
41 #define clamp(v, f, c) (max(min((v), (c)), (f)))
44 #define min_t(t, a, b) \
50 #define max_t(t, a, b) \
57 #define clamp_t(t, v, f, c) \
62 clamp(_tv, _tf, _tc); \
65 #endif /* CCAN_MINMAX_H */