diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-12-31 15:13:32 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-12-31 15:13:32 -0500 |
| commit | dbae987f1fb54da795185a03f4c00d56a639f8cd (patch) | |
| tree | 40a4d00c045c29cd9af117aa01194b8c8be4fbeb /src/stdlib | |
| parent | 0f9af5f44bd2735f34a48ceb177837a5a6ef25b0 (diff) | |
Changed is_between() to be bidirectional
Diffstat (limited to 'src/stdlib')
| -rw-r--r-- | src/stdlib/bigint.c | 4 | ||||
| -rw-r--r-- | src/stdlib/bytes.c | 2 | ||||
| -rw-r--r-- | src/stdlib/intX.c.h | 2 | ||||
| -rw-r--r-- | src/stdlib/numX.c.h | 2 |
4 files changed, 6 insertions, 4 deletions
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) { |
