aboutsummaryrefslogtreecommitdiff
path: root/elymas/lib/math.ey
diff options
context:
space:
mode:
authorDrahflow <drahflow@gmx.de>2013-08-06 10:49:42 +0200
committerDrahflow <drahflow@gmx.de>2013-08-06 10:49:42 +0200
commit25e3b82ed8bb21b84f1881efa4be5d3df0a52698 (patch)
tree0c966568b1bc372180c2119d3cae68f6b275e2fb /elymas/lib/math.ey
parent7c6ad5673f860754637f62187e69c84f150de441 (diff)
First steps towards a standard library
Diffstat (limited to 'elymas/lib/math.ey')
-rw-r--r--elymas/lib/math.ey27
1 files changed, 27 insertions, 0 deletions
diff --git a/elymas/lib/math.ey b/elymas/lib/math.ey
new file mode 100644
index 0000000..db04c7b
--- /dev/null
+++ b/elymas/lib/math.ey
@@ -0,0 +1,27 @@
+# Discrete mathematics useful in computer stuff
+# More complicated stuff in sublibs
+
+<
+ # converts an array of digits into an integer
+ # i.e. [ 1 2 3 ] 10 unbase => 321
+ # i.e. [ ] 10 unbase => 0
+ # 0 -> base to convert from
+ # 1 -> array of digits
+ # 0 <- resulting integer
+ { ==b
+ _ len _ ==l dearray
+ 0 l { b mul add } rep
+ } /unbase deff
+
+ # converts an integer into an array of digits
+ # i.e. 123 10 base => [ 3 2 1 ]
+ # i.e. 0 10 base => [ ]
+ # 0 <- base to convert to
+ # 1 <- integer to convert
+ # 0 -> resulting array of digits
+ { ==b
+ [ -01 { _ } { _ b mod -01 b div } loop -- ]
+ } /base deff
+> /math defv
+
+# vim: syn=elymas