aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-12-31 15:14:07 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-12-31 15:14:07 -0500
commit41f92837bebae1de783dc7f4a8f880011c72757c (patch)
tree4730711a7c13c19c135d0432be4d1fe9b34c1f77
parent1f13fa92a87bec65d1760266b108a5485bc14c7a (diff)
parentdbae987f1fb54da795185a03f4c00d56a639f8cd (diff)
Merge branch 'dev' into static-dependencies
-rw-r--r--CHANGES.md4
-rw-r--r--api/api.md23
-rw-r--r--api/bytes.md7
-rw-r--r--api/bytes.yaml7
-rw-r--r--api/integers.md9
-rw-r--r--api/integers.yaml11
-rw-r--r--api/nums.md7
-rw-r--r--api/nums.yaml7
-rw-r--r--man/man3/tomo-Byte.is_between.39
-rw-r--r--man/man3/tomo-Int.34
-rw-r--r--man/man3/tomo-Int.is_between.311
-rw-r--r--man/man3/tomo-Num.is_between.39
-rw-r--r--src/environment.c16
-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
-rw-r--r--test/integers.tm1
18 files changed, 77 insertions, 58 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 529711a3..9b6b2cb0 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,9 @@
# Version History
+## v2025-12-31
+
+- Changed `is_between()` to be bidirectional so `(5).is_between(10, 1) == yes`
+
## v2025-12-23.2
- Fixes for OpenBSD and Mac.
diff --git a/api/api.md b/api/api.md
index d035a3fe..df8386ff 100644
--- a/api/api.md
+++ b/api/api.md
@@ -295,15 +295,16 @@ Determines if an integer is between two numbers (inclusive).
Argument | Type | Description | Default
---------|------|-------------|---------
x | `Byte` | The integer to be checked. | -
-low | `Byte` | The lower bound to check (inclusive). | -
-high | `Byte` | The upper bound to check (inclusive). | -
+low | `Byte` | One end of the range to check (inclusive); | -
+high | `Byte` | The other end of the range to check (inclusive); | -
-**Return:** `yes` if `low <= x and x <= high`, otherwise `no`
+**Return:** `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
**Example:**
```tomo
assert Byte(7).is_between(1, 10) == yes
+assert Byte(7).is_between(10, 1) == yes
assert Byte(7).is_between(100, 200) == no
assert Byte(7).is_between(1, 7) == yes
@@ -545,7 +546,7 @@ assert (255).hex(digits=4, uppercase=yes, prefix=yes) == "0x00FF"
## Int.is_between
```tomo
-Int.is_between : func(x: Int, low: Int, high: Int -> Bool)
+Int.is_between : func(x: Int, a: Int, b: Int -> Bool)
```
Determines if an integer is between two numbers (inclusive).
@@ -553,15 +554,16 @@ Determines if an integer is between two numbers (inclusive).
Argument | Type | Description | Default
---------|------|-------------|---------
x | `Int` | The integer to be checked. | -
-low | `Int` | The lower bound to check (inclusive). | -
-high | `Int` | The upper bound to check (inclusive). | -
+a | `Int` | One end of the range to check (inclusive). | -
+b | `Int` | The other end of the range to check (inclusive). | -
-**Return:** `yes` if `low <= x and x <= high`, otherwise `no`
+**Return:** `yes` if `a <= x and x <= b` or `a >= x and x >= b`, otherwise `no`
**Example:**
```tomo
assert (7).is_between(1, 10) == yes
+assert (7).is_between(10, 1) == yes
assert (7).is_between(100, 200) == no
assert (7).is_between(1, 7) == yes
@@ -1949,15 +1951,16 @@ Determines if a number is between two numbers (inclusive).
Argument | Type | Description | Default
---------|------|-------------|---------
x | `Num` | The integer to be checked. | -
-low | `Num` | The lower bound to check (inclusive). | -
-high | `Num` | The upper bound to check (inclusive). | -
+low | `Num` | One end of the range to check (inclusive). | -
+high | `Num` | The other end of the range to check (inclusive). | -
-**Return:** `yes` if `low <= x and x <= high`, otherwise `no`
+**Return:** `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
**Example:**
```tomo
assert (7.5).is_between(1, 10) == yes
+assert (7.5).is_between(10, 1) == yes
assert (7.5).is_between(100, 200) == no
assert (7.5).is_between(1, 7.5) == yes
diff --git a/api/bytes.md b/api/bytes.md
index bb54d92c..99055523 100644
--- a/api/bytes.md
+++ b/api/bytes.md
@@ -62,15 +62,16 @@ Determines if an integer is between two numbers (inclusive).
Argument | Type | Description | Default
---------|------|-------------|---------
x | `Byte` | The integer to be checked. | -
-low | `Byte` | The lower bound to check (inclusive). | -
-high | `Byte` | The upper bound to check (inclusive). | -
+low | `Byte` | One end of the range to check (inclusive); | -
+high | `Byte` | The other end of the range to check (inclusive); | -
-**Return:** `yes` if `low <= x and x <= high`, otherwise `no`
+**Return:** `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
**Example:**
```tomo
assert Byte(7).is_between(1, 10) == yes
+assert Byte(7).is_between(10, 1) == yes
assert Byte(7).is_between(100, 200) == no
assert Byte(7).is_between(1, 7) == yes
diff --git a/api/bytes.yaml b/api/bytes.yaml
index dea650e2..adf7103b 100644
--- a/api/bytes.yaml
+++ b/api/bytes.yaml
@@ -57,7 +57,7 @@ Byte.is_between:
return:
type: 'Bool'
description: >
- `yes` if `low <= x and x <= high`, otherwise `no`
+ `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
args:
x:
type: 'Byte'
@@ -66,13 +66,14 @@ Byte.is_between:
low:
type: 'Byte'
description: >
- The lower bound to check (inclusive).
+ One end of the range to check (inclusive);
high:
type: 'Byte'
description: >
- The upper bound to check (inclusive).
+ The other end of the range to check (inclusive);
example: |
assert Byte(7).is_between(1, 10) == yes
+ assert Byte(7).is_between(10, 1) == yes
assert Byte(7).is_between(100, 200) == no
assert Byte(7).is_between(1, 7) == yes
diff --git a/api/integers.md b/api/integers.md
index ef3a6a60..73779021 100644
--- a/api/integers.md
+++ b/api/integers.md
@@ -138,7 +138,7 @@ assert (255).hex(digits=4, uppercase=yes, prefix=yes) == "0x00FF"
## Int.is_between
```tomo
-Int.is_between : func(x: Int, low: Int, high: Int -> Bool)
+Int.is_between : func(x: Int, a: Int, b: Int -> Bool)
```
Determines if an integer is between two numbers (inclusive).
@@ -146,15 +146,16 @@ Determines if an integer is between two numbers (inclusive).
Argument | Type | Description | Default
---------|------|-------------|---------
x | `Int` | The integer to be checked. | -
-low | `Int` | The lower bound to check (inclusive). | -
-high | `Int` | The upper bound to check (inclusive). | -
+a | `Int` | One end of the range to check (inclusive). | -
+b | `Int` | The other end of the range to check (inclusive). | -
-**Return:** `yes` if `low <= x and x <= high`, otherwise `no`
+**Return:** `yes` if `a <= x and x <= b` or `a >= x and x >= b`, otherwise `no`
**Example:**
```tomo
assert (7).is_between(1, 10) == yes
+assert (7).is_between(10, 1) == yes
assert (7).is_between(100, 200) == no
assert (7).is_between(1, 7) == yes
diff --git a/api/integers.yaml b/api/integers.yaml
index b3c6b579..bbbd395d 100644
--- a/api/integers.yaml
+++ b/api/integers.yaml
@@ -146,22 +146,23 @@ Int.is_between:
return:
type: 'Bool'
description: >
- `yes` if `low <= x and x <= high`, otherwise `no`
+ `yes` if `a <= x and x <= b` or `a >= x and x >= b`, otherwise `no`
args:
x:
type: 'Int'
description: >
The integer to be checked.
- low:
+ a:
type: 'Int'
description: >
- The lower bound to check (inclusive).
- high:
+ One end of the range to check (inclusive).
+ b:
type: 'Int'
description: >
- The upper bound to check (inclusive).
+ The other end of the range to check (inclusive).
example: |
assert (7).is_between(1, 10) == yes
+ assert (7).is_between(10, 1) == yes
assert (7).is_between(100, 200) == no
assert (7).is_between(1, 7) == yes
diff --git a/api/nums.md b/api/nums.md
index dac5967f..1bad194d 100644
--- a/api/nums.md
+++ b/api/nums.md
@@ -574,15 +574,16 @@ Determines if a number is between two numbers (inclusive).
Argument | Type | Description | Default
---------|------|-------------|---------
x | `Num` | The integer to be checked. | -
-low | `Num` | The lower bound to check (inclusive). | -
-high | `Num` | The upper bound to check (inclusive). | -
+low | `Num` | One end of the range to check (inclusive). | -
+high | `Num` | The other end of the range to check (inclusive). | -
-**Return:** `yes` if `low <= x and x <= high`, otherwise `no`
+**Return:** `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
**Example:**
```tomo
assert (7.5).is_between(1, 10) == yes
+assert (7.5).is_between(10, 1) == yes
assert (7.5).is_between(100, 200) == no
assert (7.5).is_between(1, 7.5) == yes
diff --git a/api/nums.yaml b/api/nums.yaml
index 4561bb91..28714ab9 100644
--- a/api/nums.yaml
+++ b/api/nums.yaml
@@ -401,7 +401,7 @@ Num.is_between:
return:
type: 'Bool'
description: >
- `yes` if `low <= x and x <= high`, otherwise `no`
+ `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
args:
x:
type: 'Num'
@@ -410,13 +410,14 @@ Num.is_between:
low:
type: 'Num'
description: >
- The lower bound to check (inclusive).
+ One end of the range to check (inclusive).
high:
type: 'Num'
description: >
- The upper bound to check (inclusive).
+ The other end of the range to check (inclusive).
example: |
assert (7.5).is_between(1, 10) == yes
+ assert (7.5).is_between(10, 1) == yes
assert (7.5).is_between(100, 200) == no
assert (7.5).is_between(1, 7.5) == yes
diff --git a/man/man3/tomo-Byte.is_between.3 b/man/man3/tomo-Byte.is_between.3
index 06e53fb0..3b539ea1 100644
--- a/man/man3/tomo-Byte.is_between.3
+++ b/man/man3/tomo-Byte.is_between.3
@@ -2,7 +2,7 @@
.\" Copyright (c) 2025 Bruce Hill
.\" All rights reserved.
.\"
-.TH Byte.is_between 3 2025-11-29 "Tomo man-pages"
+.TH Byte.is_between 3 2025-12-31 "Tomo man-pages"
.SH NAME
Byte.is_between \- test if inside a range
.SH LIBRARY
@@ -23,15 +23,16 @@ lb lb lbx
l l l.
Name Type Description
x Byte The integer to be checked.
-low Byte The lower bound to check (inclusive).
-high Byte The upper bound to check (inclusive).
+low Byte One end of the range to check (inclusive);
+high Byte The other end of the range to check (inclusive);
.TE
.SH RETURN
-`yes` if `low <= x and x <= high`, otherwise `no`
+`yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
.SH EXAMPLES
.EX
assert Byte(7).is_between(1, 10) == yes
+assert Byte(7).is_between(10, 1) == yes
assert Byte(7).is_between(100, 200) == no
assert Byte(7).is_between(1, 7) == yes
.EE
diff --git a/man/man3/tomo-Int.3 b/man/man3/tomo-Int.3
index 186c0aae..64ae7bf6 100644
--- a/man/man3/tomo-Int.3
+++ b/man/man3/tomo-Int.3
@@ -2,7 +2,7 @@
.\" Copyright (c) 2025 Bruce Hill
.\" All rights reserved.
.\"
-.TH Int 3 2025-11-30 "Tomo man-pages"
+.TH Int 3 2025-12-31 "Tomo man-pages"
.SH NAME
Int \- a Tomo type
.SH LIBRARY
@@ -59,7 +59,7 @@ For more, see:
.TP
-.BI Int.is_between\ :\ func(x:\ Int,\ low:\ Int,\ high:\ Int\ ->\ Bool)
+.BI Int.is_between\ :\ func(x:\ Int,\ a:\ Int,\ b:\ Int\ ->\ Bool)
Determines if an integer is between two numbers (inclusive).
For more, see:
diff --git a/man/man3/tomo-Int.is_between.3 b/man/man3/tomo-Int.is_between.3
index 8087e0d0..fd54eb41 100644
--- a/man/man3/tomo-Int.is_between.3
+++ b/man/man3/tomo-Int.is_between.3
@@ -2,14 +2,14 @@
.\" Copyright (c) 2025 Bruce Hill
.\" All rights reserved.
.\"
-.TH Int.is_between 3 2025-11-29 "Tomo man-pages"
+.TH Int.is_between 3 2025-12-31 "Tomo man-pages"
.SH NAME
Int.is_between \- test if an int is in a range
.SH LIBRARY
Tomo Standard Library
.SH SYNOPSIS
.nf
-.BI Int.is_between\ :\ func(x:\ Int,\ low:\ Int,\ high:\ Int\ ->\ Bool)
+.BI Int.is_between\ :\ func(x:\ Int,\ a:\ Int,\ b:\ Int\ ->\ Bool)
.fi
.SH DESCRIPTION
Determines if an integer is between two numbers (inclusive).
@@ -23,15 +23,16 @@ lb lb lbx
l l l.
Name Type Description
x Int The integer to be checked.
-low Int The lower bound to check (inclusive).
-high Int The upper bound to check (inclusive).
+a Int One end of the range to check (inclusive).
+b Int The other end of the range to check (inclusive).
.TE
.SH RETURN
-`yes` if `low <= x and x <= high`, otherwise `no`
+`yes` if `a <= x and x <= b` or `a >= x and x >= b`, otherwise `no`
.SH EXAMPLES
.EX
assert (7).is_between(1, 10) == yes
+assert (7).is_between(10, 1) == yes
assert (7).is_between(100, 200) == no
assert (7).is_between(1, 7) == yes
.EE
diff --git a/man/man3/tomo-Num.is_between.3 b/man/man3/tomo-Num.is_between.3
index 4276c8e3..ea78d895 100644
--- a/man/man3/tomo-Num.is_between.3
+++ b/man/man3/tomo-Num.is_between.3
@@ -2,7 +2,7 @@
.\" Copyright (c) 2025 Bruce Hill
.\" All rights reserved.
.\"
-.TH Num.is_between 3 2025-11-29 "Tomo man-pages"
+.TH Num.is_between 3 2025-12-31 "Tomo man-pages"
.SH NAME
Num.is_between \- check if a number is in a range
.SH LIBRARY
@@ -23,15 +23,16 @@ lb lb lbx
l l l.
Name Type Description
x Num The integer to be checked.
-low Num The lower bound to check (inclusive).
-high Num The upper bound to check (inclusive).
+low Num One end of the range to check (inclusive).
+high Num The other end of the range to check (inclusive).
.TE
.SH RETURN
-`yes` if `low <= x and x <= high`, otherwise `no`
+`yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
.SH EXAMPLES
.EX
assert (7.5).is_between(1, 10) == yes
+assert (7.5).is_between(10, 1) == yes
assert (7.5).is_between(100, 200) == no
assert (7.5).is_between(1, 7.5) == yes
.EE
diff --git a/src/environment.c b/src/environment.c
index 24d586d2..fb8bd766 100644
--- a/src/environment.c
+++ b/src/environment.c
@@ -101,7 +101,7 @@ env_t *global_env(bool source_mapping) {
"Byte", Type(ByteType), Text("Byte_t"), Text("Byte$info"),
{"get_bit", "Byte$get_bit", "func(x:Byte, bit_index:Int -> Bool)"}, //
{"hex", "Byte$hex", "func(byte:Byte, uppercase=yes, prefix=no -> Text)"}, //
- {"is_between", "Byte$is_between", "func(x:Byte, low:Byte, high:Byte -> Bool)"}, //
+ {"is_between", "Byte$is_between", "func(x:Byte, a:Byte, b:Byte -> Bool)"}, //
{"max", "Byte$max", "Byte"}, //
{"min", "Byte$min", "Byte"}, //
{"parse", "Byte$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Byte?)"}, //
@@ -118,7 +118,7 @@ env_t *global_env(bool source_mapping) {
{"gcd", "Int$gcd", "func(x,y:Int -> Int)"}, //
{"get_bit", "Int$get_bit", "func(x,bit_index:Int -> Bool)"}, //
{"hex", "Int$hex", "func(i:Int, digits=0, uppercase=yes, prefix=yes -> Text)"}, //
- {"is_between", "Int$is_between", "func(x:Int,low:Int,high:Int -> Bool)"}, //
+ {"is_between", "Int$is_between", "func(x:Int, a:Int, b:Int -> Bool)"}, //
{"is_prime", "Int$is_prime", "func(x:Int,reps=50 -> Bool)"}, //
{"left_shifted", "Int$left_shifted", "func(x,y:Int -> Int)"}, //
{"minus", "Int$minus", "func(x,y:Int -> Int)"}, //
@@ -146,7 +146,7 @@ env_t *global_env(bool source_mapping) {
{"parse", "Int64$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int64?)"}, //
{"get_bit", "Int64$get_bit", "func(x:Int64, bit_index:Int -> Bool)"}, //
{"hex", "Int64$hex", "func(i:Int64, digits=0, uppercase=yes, prefix=yes -> Text)"}, //
- {"is_between", "Int64$is_between", "func(x:Int64,low:Int64,high:Int64 -> Bool)"}, //
+ {"is_between", "Int64$is_between", "func(x:Int64, a:Int64, b:Int64 -> Bool)"}, //
{"max", "Int64$max", "Int64"}, //
{"min", "Int64$min", "Int64"}, //
{"modulo", "Int64$modulo", "func(x,y:Int64 -> Int64)"}, //
@@ -168,7 +168,7 @@ env_t *global_env(bool source_mapping) {
{"parse", "Int32$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int32?)"}, //
{"get_bit", "Int32$get_bit", "func(x:Int32, bit_index:Int -> Bool)"}, //
{"hex", "Int32$hex", "func(i:Int32, digits=0, uppercase=yes, prefix=yes -> Text)"}, //
- {"is_between", "Int32$is_between", "func(x:Int32,low:Int32,high:Int32 -> Bool)"}, //
+ {"is_between", "Int32$is_between", "func(x:Int32, a:Int32, b:Int32 -> Bool)"}, //
{"max", "Int32$max", "Int32"}, //
{"min", "Int32$min", "Int32"}, //
{"modulo", "Int32$modulo", "func(x,y:Int32 -> Int32)"}, //
@@ -190,7 +190,7 @@ env_t *global_env(bool source_mapping) {
{"parse", "Int16$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int16?)"}, //
{"get_bit", "Int16$get_bit", "func(x:Int16, bit_index:Int -> Bool)"}, //
{"hex", "Int16$hex", "func(i:Int16, digits=0, uppercase=yes, prefix=yes -> Text)"}, //
- {"is_between", "Int16$is_between", "func(x:Int16,low:Int16,high:Int16 -> Bool)"}, //
+ {"is_between", "Int16$is_between", "func(x:Int16, a:Int16, b:Int16 -> Bool)"}, //
{"max", "Int16$max", "Int16"}, //
{"min", "Int16$min", "Int16"}, //
{"modulo", "Int16$modulo", "func(x,y:Int16 -> Int16)"}, //
@@ -212,7 +212,7 @@ env_t *global_env(bool source_mapping) {
{"parse", "Int8$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int8?)"}, //
{"get_bit", "Int8$get_bit", "func(x:Int8, bit_index:Int -> Bool)"}, //
{"hex", "Int8$hex", "func(i:Int8, digits=0, uppercase=yes, prefix=yes -> Text)"}, //
- {"is_between", "Int8$is_between", "func(x:Int8,low:Int8,high:Int8 -> Bool)"}, //
+ {"is_between", "Int8$is_between", "func(x:Int8, a:Int8, b:Int8 -> Bool)"}, //
{"max", "Int8$max", "Int8"}, //
{"min", "Int8$min", "Int8"}, //
{"modulo", "Int8$modulo", "func(x,y:Int8 -> Int8)"}, //
@@ -234,7 +234,7 @@ env_t *global_env(bool source_mapping) {
{"clamped", "Num$clamped", "func(x,low,high:Num -> Num)"}, //
{"percent", "Num$percent", "func(n:Num,precision=0.01 -> Text)"}, //
{"with_precision", "Num$with_precision", "func(n:Num,precision:Num -> Num)"}, //
- {"is_between", "Num$is_between", "func(x:Num,low:Num,high:Num -> Bool)"}, //
+ {"is_between", "Num$is_between", "func(x:Num, a:Num, b:Num -> Bool)"}, //
{"isinf", "Num$isinf", "func(n:Num -> Bool)"}, //
{"isfinite", "Num$isfinite", "func(n:Num -> Bool)"}, //
{"modulo", "Num$mod", "func(x,y:Num -> Num)"}, //
@@ -264,7 +264,7 @@ env_t *global_env(bool source_mapping) {
{"clamped", "Num32$clamped", "func(x,low,high:Num32 -> Num32)"}, //
{"percent", "Num32$percent", "func(n:Num32,precision=Num32(.01) -> Text)"}, //
{"with_precision", "Num32$with_precision", "func(n:Num32,precision:Num32 -> Num32)"}, //
- {"is_between", "Num32$is_between", "func(x:Num32,low:Num32,high:Num32 -> Bool)"}, //
+ {"is_between", "Num32$is_between", "func(x:Num32, a:Num32, b:Num32 -> Bool)"}, //
{"isinf", "Num32$isinf", "func(n:Num32 -> Bool)"}, //
{"isfinite", "Num32$isfinite", "func(n:Num32 -> Bool)"}, //
C(2_SQRTPI), C(E), C(PI_2), C(2_PI), C(1_PI), C(LN10), C(LN2), C(LOG2E), C(PI), C(PI_4), C(SQRT2),
diff --git a/src/stdlib/bigint.c b/src/stdlib/bigint.c
index d47dfee8..11270848 100644
--- a/src/stdlib/bigint.c
+++ b/src/stdlib/bigint.c
@@ -140,7 +140,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 2b2a6507..25f95de1 100644
--- a/src/stdlib/bytes.c
+++ b/src/stdlib/bytes.c
@@ -32,7 +32,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 19f838d7..e6153ac9 100644
--- a/src/stdlib/intX.c.h
+++ b/src/stdlib/intX.c.h
@@ -119,7 +119,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 2d652ebe..bef78c5b 100644
--- a/src/stdlib/numX.c.h
+++ b/src/stdlib/numX.c.h
@@ -193,7 +193,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) {
diff --git a/test/integers.tm b/test/integers.tm
index 67175f7a..2d07beda 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -94,6 +94,7 @@ func main()
assert (3).is_between(1, 5) == yes
assert (3).is_between(1, 3) == yes
+ assert (3).is_between(5, 1) == yes
assert (3).is_between(100, 200) == no
assert (6).get_bit(1) == no