From 352e09970c9479140304de42e5ec42470f7e6528 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 20 Dec 2022 16:45:35 +0100 Subject: [PATCH] Math max/min now take multiple arguments. --- lib/std/math.c3 | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/std/math.c3 b/lib/std/math.c3 index ebbed32ba..2aaa4b2d7 100644 --- a/lib/std/math.c3 +++ b/lib/std/math.c3 @@ -202,13 +202,35 @@ macro log10(x) = $$log10(x); * @require types::is_numerical($typeof(x)) `The input must be a floating point value or float vector` * @require types::is_same($typeof(x), $typeof(y)) `The input types must be equal` **/ -macro max(x, y) = $$max(x, y); +macro max(x, y, ...) +{ + $if ($vacount == 0): + return $$max(x, y); + $else: + var m = $$max(x, y); + $for (var $i = 0; $i < $vacount; $i++): + m = $$max(m, $vaarg($i)); + $endfor; + return m; + $endif; +} /** * @require types::is_numerical($typeof(x)) `The input must be a numerical value or numerical vector` * @require types::is_same($typeof(x), $typeof(y)) `The input types must be equal` **/ -macro min(x, y) = $$min(x, y); +macro min(x, y, ...) +{ + $if ($vacount == 0): + return $$min(x, y); + $else: + var m = $$min(x, y); + $for (var $i = 0; $i < $vacount; $i++): + m = $$min(m, $vaarg($i)); + $endfor; + return m; + $endif; +} /** * @require types::@is_float(a) `The input must be a floating point value`