aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2024-11-13 18:47:43 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commit1ae9094ba674a087da768d639d4600fbbbdbbd27 (patch)
treeefd94c638170d31de5ffbcfc7bf8a1a1b2dc3137
parentsmall fixes (diff)
downloadalive-1ae9094ba674a087da768d639d4600fbbbdbbd27.tar.gz
alive-1ae9094ba674a087da768d639d4600fbbbdbbd27.zip
lib: add // to math
-rw-r--r--alv-lib/math-simple.moon10
-rw-r--r--alv-lib/math.moon9
2 files changed, 19 insertions, 0 deletions
diff --git a/alv-lib/math-simple.moon b/alv-lib/math-simple.moon
index bf14768..9d5e09d 100644
--- a/alv-lib/math-simple.moon
+++ b/alv-lib/math-simple.moon
@@ -81,6 +81,15 @@ div = Constant.meta
value: class extends ReduceOp
fn: (a, b) -> a / b
+idiv = Constant.meta
+ meta:
+ name: 'idiv'
+ summary: "Divide values and floor."
+ examples: { '(// a b [c…])', '(idiv a b [c…])' }
+ description: "Divide `a` by all other arguments, flooring each time."
+ value: class extends ReduceOp
+ fn: (a, b) -> mat.floor a / b
+
pow = Constant.meta
meta:
name: 'pow'
@@ -185,6 +194,7 @@ For vectorized operators and matrix multiplication, use [math/][]."
:sub, '-': sub
:mul, '*': mul
:div, '/': div
+ :idiv, '//': idiv
:pow, '^': pow
:mod, '%': mod
diff --git a/alv-lib/math.moon b/alv-lib/math.moon
index c52fd35..33f215c 100644
--- a/alv-lib/math.moon
+++ b/alv-lib/math.moon
@@ -202,6 +202,14 @@ div = Constant.meta
value: func_op (reduce_fn (a, b) -> a / b), num\rep 2, nil
-- @TODO: block matrix-matrix division
+idiv = Constant.meta
+ meta:
+ name: 'idiv'
+ summary: "Divide values and floor."
+ examples: { '(// a b [c…])', '(idiv a b [c…])' }
+ description: "Divide `a` by all other arguments, flooring each time."
+ value: func_op (reduce_fn (a, b) -> math.floor a / b), num\rep 2, nil
+
pow = Constant.meta
meta:
name: 'pow'
@@ -302,6 +310,7 @@ as it handles matrix-matrix and matrix-vector multiplication according to linear
:sub, '-': sub
:mul, '*': mul
:div, '/': div
+ :idiv, '//': idiv
:pow, '^': pow
:mod, '%': mod