]> mj.ucw.cz Git - libucw.git/commitdiff
Macros: CLAMP now accepts arbitrary types, not only ints
authorMartin Mares <mj@ucw.cz>
Sun, 9 Nov 2014 13:56:41 +0000 (14:56 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 9 Nov 2014 13:56:41 +0000 (14:56 +0100)
ucw/lib.h

index dffccba4a876a1dc2e244d3db185d3d2f9fe798e..5df7d6e1450d2df93cb1a17331941fd6da5fedc4 100644 (file)
--- a/ucw/lib.h
+++ b/ucw/lib.h
@@ -68,7 +68,7 @@
 
 #define MIN(a,b) (((a)<(b))?(a):(b))                   /** Minimum of two numbers **/
 #define MAX(a,b) (((a)>(b))?(a):(b))                   /** Maximum of two numbers **/
-#define CLAMP(x,min,max) ({ int _t=x; (_t < min) ? min : (_t > max) ? max : _t; })     /** Clip a number @x to interval [@min,@max] **/
+#define CLAMP(x,min,max) ({ typeof(x) _t=x; (_t < min) ? min : (_t > max) ? max : _t; })       /** Clip a number @x to interval [@min,@max] **/
 #define ABS(x) ((x) < 0 ? -(x) : (x))                  /** Absolute value **/
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))         /** The number of elements of an array **/
 #define STRINGIFY(x) #x                                        /** Convert macro parameter to a string **/