aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-18 23:20:54 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-18 23:20:54 -0400
commitb76fbd3beba08c098c6d18578230f9edbc4d3a3d (patch)
treec87b3488a3846523f4f56c9685ffafa06fdc771b /api
parent0864d82c3f8634f449186f775b0bbcaa872bb43c (diff)
Add Int:clamped() and Num:clamped()
Diffstat (limited to 'api')
-rw-r--r--api/integers.md34
-rw-r--r--api/nums.md28
2 files changed, 60 insertions, 2 deletions
diff --git a/api/integers.md b/api/integers.md
index acbab60c..653322fd 100644
--- a/api/integers.md
+++ b/api/integers.md
@@ -302,7 +302,8 @@ The next prime number greater than `x`.
**Example:**
```tomo
-11:next_prime() // 13
+>> 11:next_prime()
+= 13
```
---
@@ -334,5 +335,34 @@ The previous prime number less than `x`.
**Example:**
```tomo
-11:prev_prime() // 7
+>> 11:prev_prime()
+= 7
+```
+
+---
+
+## `clamped`
+
+**Description:**
+Returns the given number clamped between two values so that it is within
+that range.
+
+**Usage:**
+```tomo
+clamped(x, low, high: Int) -> Int
+```
+
+**Parameters:**
+
+- `x`: The integer to clamp.
+- `low`: The lowest value the result can take.
+- `high`: The highest value the result can take.
+
+**Returns:**
+The first argument clamped between the other two arguments.
+
+**Example:**
+```tomo
+>> 2:clamped(5, 10)
+= 5
```
diff --git a/api/nums.md b/api/nums.md
index 5f28b1a3..5b258010 100644
--- a/api/nums.md
+++ b/api/nums.md
@@ -1344,3 +1344,31 @@ The Bessel function of the second kind of order 1 of `x`.
>> 1.0:y1()
= 0.4401
```
+
+---
+
+## `clamped`
+
+**Description:**
+Returns the given number clamped between two values so that it is within
+that range.
+
+**Usage:**
+```tomo
+clamped(x, low, high: Num) -> Num
+```
+
+**Parameters:**
+
+- `x`: The number to clamp.
+- `low`: The lowest value the result can take.
+- `high`: The highest value the result can take.
+
+**Returns:**
+The first argument clamped between the other two arguments.
+
+**Example:**
+```tomo
+>> 2.5:clamped(5.5, 10.5)
+= 5.5
+```