diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-02-01 23:13:40 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-02-01 23:13:40 +0000 |
commit | 684442d308ec7789fe38697e810b4c4fe9a6c0e0 (patch) | |
tree | e52c8522ba1540dd4328802c7fcba4ac9767b208 /functions.c | |
parent | 178745ae557eacb2326a6da5cffa2d0fb48fd7ac (diff) |
Add encode and decode ⊥ ⊤
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 28 |
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); |