From: Martin Mares Date: Sun, 9 Nov 2014 13:56:41 +0000 (+0100) Subject: Macros: CLAMP now accepts arbitrary types, not only ints X-Git-Tag: v6.2~8 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=19a865da126762355188d095ec3a82a4f6616e0b;p=libucw.git Macros: CLAMP now accepts arbitrary types, not only ints --- diff --git a/ucw/lib.h b/ucw/lib.h index dffccba4..5df7d6e1 100644 --- 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 **/