From 19a865da126762355188d095ec3a82a4f6616e0b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 9 Nov 2014 14:56:41 +0100 Subject: [PATCH] Macros: CLAMP now accepts arbitrary types, not only ints --- ucw/lib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 **/ -- 2.39.2