From 30bd5e6cfe0a33e40d4fa10d628e4977afab5df1 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Fri, 9 Nov 2018 15:50:48 +0000 Subject: [PATCH] Added function to take the max and min of 4 numbers. --- src/minmax.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/minmax.h b/src/minmax.h index 90dd87968a..8964b4a477 100644 --- a/src/minmax.h +++ b/src/minmax.h @@ -71,4 +71,36 @@ max(_temp, _z); \ }) +/** + * @brief Minimum of four numbers + * + * This macro evaluates its arguments exactly once. + */ +#define min4(x, y, z, w) \ + ({ \ + const __typeof__(x) _x = (x); \ + const __typeof__(y) _y = (y); \ + const __typeof__(z) _z = (z); \ + const __typeof__(w) _w = (w); \ + const __typeof__(x) _temp1 = min(_x, _y); \ + const __typeof__(x) _temp2 = min(_z, _w); \ + min(_temp1, _temp2);\ + }) + +/** + * @brief Maximum of four numbers + * + * This macro evaluates its arguments exactly once. + */ +#define max4(x, y, z, w) \ + ({ \ + const __typeof__(x) _x = (x); \ + const __typeof__(y) _y = (y); \ + const __typeof__(z) _z = (z); \ + const __typeof__(w) _w = (w); \ + const __typeof__(x) _temp1 = max(_x, _y); \ + const __typeof__(x) _temp2 = max(_z, _w); \ + max(_temp1, _temp2);\ + }) + #endif /* SWIFT_MINMAX_H */ -- GitLab