summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/functions.c b/functions.c
index f1c4b0d..b1003fa 100644
--- a/functions.c
+++ b/functions.c
@@ -13,7 +13,7 @@ fnmonad monadfunctiondefs[] = {
fnRecip, /* ÷ */
fnExponent, /* * */
fnNaturalLog, /* ⍟ */
- 0, /* ⌹ */
+ fnMatrixInverse, /* ⌹ */
fnPiTimes, /* ○ */
fnFactorial, /* ! */
fnRoll, /* ? */
@@ -69,7 +69,7 @@ fndyad dyadfunctiondefs[] = {
fnDivide, /* ÷ */
fnPower, /* * */
fnLogarithm, /* ⍟ */
- 0, /* ⌹ */
+ fnMatrixDivide, /* ⌹ */
fnCircular, /* ○ */
fnBinomial, /* ! */
fnDeal, /* ? */
@@ -316,6 +316,23 @@ fnNaturalLog(Array *right)
}
Array *
+fnMatrixInverse(Array *right)
+{
+ if(right->type != AtypeInt && right->type != AtypeFloat)
+ throwerror(nil, EType);
+ if(right->rank > 2)
+ throwerror(nil, ERank);
+
+ if(right->rank == 0)
+ return rundfn(L"⌹1 1⍴⍵", nil, nil, nil, right);
+ if(right->rank == 1)
+ return rundfn(L"⌹(1⍪⍨⍴⍵)⍴⍵", nil, nil, nil, right);
+
+ throwerror(L"Matrix inverse", ENotImplemented);
+ return nil;
+}
+
+Array *
fnPiTimes(Array *right)
{
Array *pi = mkscalarfloat(PI);
@@ -982,6 +999,12 @@ SCALAR_FUNCTION_2(fnLogarithm, 1, left->type,
break;
)
+Array *
+fnMatrixDivide(Array *left, Array *right)
+{
+ return rundfn(L"⍺+.×⌹⍵", nil, nil, left, right);
+}
+
SCALAR_FUNCTION_2(fnCircular, 1, AtypeFloat,
case AtypeFloat:{
double v = right->floatdata[i];