From 4da0422c5a71fd4fe5e4c4472414323c47b39247 Mon Sep 17 00:00:00 2001 From: r4 Date: Sun, 29 May 2022 20:46:25 +0200 Subject: [PATCH] =?UTF-8?q?actually=20add=20number.h=20itself=20?= =?UTF-8?q?=F0=9F=A4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/ds/number.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 include/ds/number.h diff --git a/include/ds/number.h b/include/ds/number.h new file mode 100644 index 0000000..39ad5d7 --- /dev/null +++ b/include/ds/number.h @@ -0,0 +1,12 @@ +#ifndef __DS_NUMBER_H__ +#define __DS_NUMBER_H__ + +/* Returns the smaller/larger value of x and y. */ +#define min(x, y) ((x) < (y) ? (x) : y) +#define max(x, y) ((x) > (y) ? (x) : y) + +/* Tries to calculate x - y. If the result would be negative, returns 0 instead. + * Can safely be used on unsigned types like size_t. */ +#define sub_clamped(x, y) ((x) > (y) ? (x) - (y) : 0) + +#endif