aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/bigint.c4
-rw-r--r--src/stdlib/bytes.c2
-rw-r--r--src/stdlib/intX.c.h2
-rw-r--r--src/stdlib/numX.c.h2
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) {