]> mj.ucw.cz Git - home-hw.git/commitdiff
Library: CLAMP
authorMartin Mares <mj@ucw.cz>
Tue, 16 Jul 2019 16:27:19 +0000 (18:27 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 16 Jul 2019 16:27:19 +0000 (18:27 +0200)
lib/util.h

index 8aa02f438cbfdd1c59ef326aef0b1941c22f0cb2..b37c527f603f9003373c97bd4f85d0f753f4ac70 100644 (file)
@@ -23,6 +23,7 @@ typedef int32_t s32;
 
 #define MIN(x,y) ((x) < (y) ? (x) : (y))
 #define MAX(x,y) ((x) > (y) ? (x) : (y))
+#define CLAMP(x,min,max) ({ typeof(x) _t=x; (_t < min) ? min : (_t > max) ? max : _t; })
 
 #define UNUSED __attribute__((unused))