summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apl9.h3
-rw-r--r--inverse.c13
-rw-r--r--mkfile1
-rw-r--r--operators.c8
4 files changed, 24 insertions, 1 deletions
diff --git a/apl9.h b/apl9.h
index c275d73..7c03918 100644
--- a/apl9.h
+++ b/apl9.h
@@ -264,6 +264,9 @@ void throwerror(Rune *, int);
memcpy(globalerror.jmp, old, sizeof(jmp_buf));\
}
+/* inverse.c */
+Function inverse(Function);
+
/* Monadic functions from function.c */
Array *fnNegate(Array *);
Array *fnSign(Array *);
diff --git a/inverse.c b/inverse.c
new file mode 100644
index 0000000..b37664b
--- /dev/null
+++ b/inverse.c
@@ -0,0 +1,13 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+#include "apl9.h"
+
+Function
+inverse(Function f)
+{
+ Rune *msg = runesmprint("No inverse defined for %S", ppfunction(f));
+ throwerror(msg, EDomain);
+ return f;
+} \ No newline at end of file
diff --git a/mkfile b/mkfile
index ab00568..017cc1a 100644
--- a/mkfile
+++ b/mkfile
@@ -14,6 +14,7 @@ OFILES=\
quadnames.$O\
error.$O\
hybrids.$O\
+ inverse.$O\
HFILES=\
apl9.h\
diff --git a/operators.c b/operators.c
index 17ba76e..1ecb8aa 100644
--- a/operators.c
+++ b/operators.c
@@ -101,8 +101,14 @@ opPower(Datum *lefto, Datum *righto, Array *left, Array *right)
else
code = L"next←⍶⍵ ⋄ next⍹⍵:⍵ ⋄ ∇next";
}else if(righto->tag == ArrayTag){
- if(righto->array->type != AtypeInt || righto->array->rank != 0 || righto->array->size != 1 || righto->array->intdata[0] < 0)
+ if(righto->array->type != AtypeInt || righto->array->rank != 0 || righto->array->size != 1)
throwerror(L"right operand to ⍣", EDomain);
+ vlong times = righto->array->intdata[0];
+ if(times < 0){
+ lefto->func = inverse(lefto->func);
+ times = -times;
+ }
+ righto->array->intdata[0] = times;
if(left)
code = L"⍹=0:⍵ ⋄ ⍺ ⍶⍙(⍹-1)⊢⍺⍶⍵";
else