Range and Interval Operations
include/math/range.h View source View on GitHubStructs
Section titled “Structs”Macros
Section titled “Macros”IN_RANGE
Section titled “IN_RANGE”#define IN_RANGE(x, min, max) source Expansion
#define IN_RANGE(x, min, max) \
({ \
__auto_type __ir_x = (x); \
__auto_type __ir_lo = (min); \
__auto_type __ir_hi = (max); \
typedef ct_common_type_2(__ir_x, __ir_lo) __ir_t1; \
typedef ct_common_type_2((__ir_t1) 0, __ir_hi) __ir_t; \
ct_typecheck_widenable_to((__ir_t) 0, x); \
ct_typecheck_widenable_to((__ir_t) 0, min); \
ct_typecheck_widenable_to((__ir_t) 0, max); \
__ir_t __ir_v = (__ir_t) __ir_x; \
__ir_t __ir_l = (__ir_t) __ir_lo; \
__ir_t __ir_h = (__ir_t) __ir_hi; \
(void) enforce(__ir_l <= __ir_h); \
(__ir_v >= __ir_l) && (__ir_v <= __ir_h); \
}) #define RANGE(min, max) source RANGE_DEFINE
Section titled “RANGE_DEFINE”#define RANGE_DEFINE(type, name) source Expansion
#define RANGE_DEFINE(type, name) \
struct { \
type low; \
type hi; \
} name RANGE_CONTAINS
Section titled “RANGE_CONTAINS”#define RANGE_CONTAINS(r, val) source Expansion
#define RANGE_CONTAINS(r, val) \
({ \
__auto_type __rc_r = (r); \
__auto_type __rc_val = (val); \
(__rc_val >= __rc_r.low && __rc_val <= __rc_r.hi); \
}) RANGE_VALID
Section titled “RANGE_VALID”#define RANGE_VALID(r) source Expansion
#define RANGE_VALID(r) \
({ \
__auto_type __rv_r = (r); \
(__rv_r.low <= __rv_r.hi); \
})