PER Firmware
Loading...
Searching...
No Matches
clamp.h
Go to the documentation of this file.
1
#ifndef CLAMP_H
2
#define CLAMP_H
3
14
#define DEFINE_CLAMP(type, name) \
15
[[gnu::always_inline]] \
16
static inline type clamp_##name(type input, type lower, type upper) { \
17
if (input < lower) return lower; \
18
if (input > upper) return upper; \
19
return input; \
20
}
21
22
DEFINE_CLAMP
(
int
,
int
)
23
DEFINE_CLAMP
(
unsigned
int
, uint)
24
DEFINE_CLAMP
(
long
,
long
)
25
DEFINE_CLAMP
(
unsigned
long
, ulong)
26
DEFINE_CLAMP
(
float
,
float
)
27
28
#define CLAMP(input, lower_bound, upper_bound) \
29
_Generic((input) + (lower_bound) + (upper_bound), \
30
int: clamp_int, \
31
unsigned int: clamp_uint, \
32
long: clamp_long, \
33
unsigned long: clamp_ulong, \
34
float: clamp_float \
35
)(input, lower_bound, upper_bound)
36
37
38
#endif
// CLAMP_H
DEFINE_CLAMP
#define DEFINE_CLAMP(type, name)
Definition
clamp.h:14
firmware
common
utils
clamp.h
Generated by
1.12.0