X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=minmax.h;h=ec0848c0d67c7f84c549868e60f5063150a0cdeb;hp=e5c2f584714fe877d7b119d16683f0a3cdd7146f;hb=dc54b6ca3209c2da3df30e96d097f6de29d56d24;hpb=5ffb051d716725b7c39cf115af779a29d09b62a5 diff --git a/minmax.h b/minmax.h index e5c2f584..ec0848c0 100644 --- a/minmax.h +++ b/minmax.h @@ -2,10 +2,24 @@ #define FIO_MIN_MAX_H #ifndef min -#define min(a, b) ((a) < (b) ? (a) : (b)) +#define min(x,y) ({ \ + __typeof__(x) _x = (x); \ + __typeof__(y) _y = (y); \ + (void) (&_x == &_y); \ + _x < _y ? _x : _y; }) #endif + #ifndef max -#define max(a, b) ((a) > (b) ? (a) : (b)) +#define max(x,y) ({ \ + __typeof__(x) _x = (x); \ + __typeof__(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; }) #endif +#define min_not_zero(x, y) ({ \ + __typeof__(x) __x = (x); \ + __typeof__(y) __y = (y); \ + __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) + #endif