Skip to content

Commit 1e9c6f0

Browse files
committed
feat(math): add clamp min, val, max func
1 parent 603a0e8 commit 1e9c6f0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/math.fnk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ sign = Math.sign
6666
max = Math.max
6767
min = Math.min
6868

69+
clamp = fn min_val, value, max_val:
70+
max min_val, min value, max_val
71+
6972
int_mul = Math.imul
7073

7174
random = Math.random

src/math.test.fnk

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{describe, it, expect, to_equal} = import '@fink/jest'
22

3-
{π} = import './math'
3+
, clamp} = import './math'
44

55

66
describe 'math', fn:
@@ -9,3 +9,13 @@ describe 'math', fn:
99
π
1010
to_equal Math.PI
1111

12+
13+
it 'clamp', fn:
14+
expect
15+
clamp 0, -1, 2
16+
to_equal 0
17+
18+
expect
19+
clamp 0, 3, 2
20+
to_equal 2
21+

0 commit comments

Comments
 (0)