2021-05-18 10:51:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-05-18 18:54:56 +00:00
|
|
|
#ifndef MAX
|
|
|
|
|
|
|
|
#define MAX(a, b) \
|
|
|
|
({ \
|
|
|
|
__typeof__(a) _a = (a); \
|
|
|
|
__typeof__(b) _b = (b); \
|
|
|
|
_a > _b ? _a : _b; \
|
|
|
|
})
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a, b) \
|
|
|
|
({ \
|
|
|
|
__typeof__(a) _a = (a); \
|
|
|
|
__typeof__(b) _b = (b); \
|
|
|
|
_a < _b ? _a : _b; \
|
|
|
|
})
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CLAMP
|
|
|
|
#define CLAMP(x, upper, lower) (MIN(upper, MAX(x, lower)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// need some common semantics for those two
|
|
|
|
#ifndef SIZEOF_ARRAY
|
|
|
|
#define SIZEOF_ARRAY(arr) (sizeof(arr) / sizeof(arr[0]))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef COUNT_OF
|
2021-05-18 10:51:00 +00:00
|
|
|
#define COUNT_OF(x) (sizeof(x) / sizeof(x[0]))
|
2021-05-18 18:54:56 +00:00
|
|
|
#endif
|