From 82f5f05bb9440b758ae5e4a7c168e36ecff06db5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 7 Apr 2025 03:21:58 -0400 Subject: Move clamped() and is_between() to proper functions (not just macros) --- src/stdlib/nums.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/stdlib/nums.c') diff --git a/src/stdlib/nums.c b/src/stdlib/nums.c index 9edb8751..ed1c64be 100644 --- a/src/stdlib/nums.c +++ b/src/stdlib/nums.c @@ -76,6 +76,13 @@ public CONSTFUNC double Num$mix(double amount, double x, double y) { return (1.0-amount)*x + amount*y; } +public CONSTFUNC bool Num$is_between(const double x, const double low, const double high) { + return low <= x && x <= high; +} +public CONSTFUNC double Num$clamped(double x, double low, double high) { + return (x <= low) ? low : (x >= high ? high : x); +} + public OptionalNum_t Num$parse(Text_t text) { const char *str = Text$as_c_string(text); char *end = NULL; @@ -161,6 +168,14 @@ public CONSTFUNC float Num32$mix(float amount, float x, float y) { return (1.0f-amount)*x + amount*y; } +public CONSTFUNC bool Num32$is_between(const float x, const float low, const float high) { + return low <= x && x <= high; +} + +public CONSTFUNC float Num32$clamped(float x, float low, float high) { + return (x <= low) ? low : (x >= high ? high : x); +} + public OptionalNum32_t Num32$parse(Text_t text) { const char *str = Text$as_c_string(text); char *end = NULL; -- cgit v1.2.3