We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 08d01f3 commit b14396fCopy full SHA for b14396f
include/utils.h
@@ -97,3 +97,6 @@
97
#define ARCH_ENABLE_INTERRUPTS() (void)0
98
#define ARCH_DISABLE_INTERRUPTS() (void)0
99
#endif
100
+
101
+// Clamp value to lower & upper bounds
102
+#define CLAMP(v, l, u) (v < l) ? l : (v >= u) ? u : v
src/unittests/kernel/utils_test.c
@@ -4,6 +4,14 @@
4
#include <unittest/unittest.h>
5
#include <types.h>
6
7
+TEST (utils, clamp)
8
+{
9
+ EQ_SCALAR (CLAMP (0, 0, 0), 0);
10
+ EQ_SCALAR (CLAMP (-10, 1, 2), 1);
11
+ EQ_SCALAR (CLAMP (10, 1, 2), 2);
12
+ END();
13
+}
14
15
TEST (utils, bit_set)
16
{
17
EQ_SCALAR (BIT_SET (0x10, 0), 0b00010001);
@@ -196,4 +204,5 @@ int main() {
196
204
bytes_to_pageframes_floor();
197
205
bit_set();
198
206
bit_clear();
207
+ clamp();
199
208
}
0 commit comments