From dbae987f1fb54da795185a03f4c00d56a639f8cd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 31 Dec 2025 15:13:32 -0500 Subject: Changed is_between() to be bidirectional --- src/stdlib/bigint.c | 4 +++- src/stdlib/bytes.c | 2 +- src/stdlib/intX.c.h | 2 +- src/stdlib/numX.c.h | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/stdlib') diff --git a/src/stdlib/bigint.c b/src/stdlib/bigint.c index c9bfb68e..e2935332 100644 --- a/src/stdlib/bigint.c +++ b/src/stdlib/bigint.c @@ -102,7 +102,9 @@ CONSTFUNC Int_t Int$clamped(Int_t x, Int_t low, Int_t high) { public CONSTFUNC bool Int$is_between(const Int_t x, const Int_t low, const Int_t high) { - return Int$compare_value(low, x) <= 0 && Int$compare_value(x, high) <= 0; + int32_t low_cmp = Int$compare_value(x, low); + int32_t high_cmp = Int$compare_value(x, high); + return (low_cmp >= 0 && high_cmp <= 0) || (low_cmp <= 0 && high_cmp >= 0); } public diff --git a/src/stdlib/bytes.c b/src/stdlib/bytes.c index 2b8dab4d..9874f222 100644 --- a/src/stdlib/bytes.c +++ b/src/stdlib/bytes.c @@ -31,7 +31,7 @@ PUREFUNC public Text_t Byte$as_text(const void *b, bool colorize, const TypeInfo public CONSTFUNC bool Byte$is_between(const Byte_t x, const Byte_t low, const Byte_t high) { - return low <= x && x <= high; + return (low <= x && x <= high) || (high <= x && x <= low); } public diff --git a/src/stdlib/intX.c.h b/src/stdlib/intX.c.h index 3e6648f7..04c8ef3b 100644 --- a/src/stdlib/intX.c.h +++ b/src/stdlib/intX.c.h @@ -116,7 +116,7 @@ PUREFUNC bool NAMESPACED(equal)(const void *x, const void *y, const TypeInfo_t * } public CONSTFUNC bool NAMESPACED(is_between)(const INT_T x, const INT_T low, const INT_T high) { - return low <= x && x <= high; + return (low <= x && x <= high) || (high <= x && x <= low); } public CONSTFUNC INT_T NAMESPACED(clamped)(INT_T x, INT_T min, INT_T max) { diff --git a/src/stdlib/numX.c.h b/src/stdlib/numX.c.h index ed91fbf5..22db3ca3 100644 --- a/src/stdlib/numX.c.h +++ b/src/stdlib/numX.c.h @@ -155,7 +155,7 @@ CONSTFUNC NUM_T NAMESPACED(mix)(NUM_T amount, NUM_T x, NUM_T y) { public CONSTFUNC bool NAMESPACED(is_between)(const NUM_T x, const NUM_T low, const NUM_T high) { - return low <= x && x <= high; + return (low <= x && x <= high) || (high <= x && x <= low); } public CONSTFUNC NUM_T NAMESPACED(clamped)(NUM_T x, NUM_T low, NUM_T high) { -- cgit v1.2.3