summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/functions.c b/functions.c
index 24fefa9..68dcbe7 100644
--- a/functions.c
+++ b/functions.c
@@ -76,8 +76,8 @@ fndyad dyadfunctiondefs[] = {
fnResidue, /* | */
fnMaximum, /* ⌈ */
fnMinimum, /* ⌊ */
- 0, /* ⊥ */
- 0, /* ⊤ */
+ fnDecode, /* ⊥ */
+ fnEncode, /* ⊤ */
fnLeft, /* ⊣ */
fnRight, /* ⊢ */
fnEqual, /* = */
@@ -1052,6 +1052,30 @@ SCALAR_FUNCTION_2(fnMinimum, 0, left->type,
)
Array *
+fnDecode(Array *left, Array *right)
+{
+ if(left->type != AtypeInt && left->type != AtypeFloat)
+ throwerror(nil, EType);
+ if(right->type != AtypeInt && right->type != AtypeFloat)
+ throwerror(nil, EType);
+ return rundfn(L"(⌽×\\1,⌽⍵∘{1↓(≢⍺)⍴⍵}⍤1⊢⍺)+.×⍵", nil, nil, left, right);
+}
+
+Array *
+fnEncode(Array *left, Array *right)
+{
+ if(left->type != AtypeInt && left->type != AtypeFloat)
+ throwerror(nil, EType);
+ if(right->type != AtypeInt && right->type != AtypeFloat)
+ throwerror(nil, EType);
+
+ if(left->rank > 1)
+ return rundfn(L"⍉(⍉⍺) (⊤⍤1) ⍵", nil, nil, left, right);
+ else
+ return rundfn(L"⎕div←1 ⋄ ((⍴⍺),⍴⍵)⍴(⌽⍺){0=≢⍺:⍬ ⋄ n←⊃⍺ ⋄ x←n|⍵ ⋄ ((1↓⍺)∇n÷⍨⍵-x)⍪x}⍵", nil, nil, left, right);
+}
+
+Array *
fnLeft(Array *left, Array *right)
{
USED(right);