X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=minmax.h;h=afc78f02e4b3f4cfe2de624d780301a54f8bc926;hp=e5c2f584714fe877d7b119d16683f0a3cdd7146f;hb=e2b7f9fb0d105de217fe97817b47c594232ac14f;hpb=1e5324e723116a5faf9da686993cc79c14d62d4b diff --git a/minmax.h b/minmax.h index e5c2f584..afc78f02 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