From f857f38f718fff586e373815a1bcad2701b4d983 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 7 Apr 2025 01:17:02 -0400 Subject: Add `is_between()` for various types --- src/stdlib/nums.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/stdlib/nums.h') diff --git a/src/stdlib/nums.h b/src/stdlib/nums.h index f3de9dc5..84d87dd5 100644 --- a/src/stdlib/nums.h +++ b/src/stdlib/nums.h @@ -32,6 +32,9 @@ CONSTFUNC bool Num$isnan(double n); double Num$nan(Text_t tag); CONSTFUNC double Num$mix(double amount, double x, double y); OptionalNum_t Num$parse(Text_t text); +MACROLIKE CONSTFUNC bool Num$is_between(const double x, const double low, const double high) { + return low <= x && x <= high; +} MACROLIKE CONSTFUNC double Num$clamped(double x, double low, double high) { return (x <= low) ? low : (x >= high ? high : x); } @@ -88,6 +91,9 @@ CONSTFUNC bool Num32$isnan(float n); CONSTFUNC float Num32$mix(float amount, float x, float y); OptionalNum32_t Num32$parse(Text_t text); float Num32$nan(Text_t tag); +MACROLIKE CONSTFUNC bool Num32$is_between(const float x, const float low, const float high) { + return low <= x && x <= high; +} MACROLIKE CONSTFUNC float Num32$clamped(float x, float low, float high) { return (x <= low) ? low : (x >= high ? high : x); } -- cgit v1.2.3