diff options
-rw-r--r-- | apl9.h | 3 | ||||
-rw-r--r-- | inverse.c | 13 | ||||
-rw-r--r-- | mkfile | 1 | ||||
-rw-r--r-- | operators.c | 8 |
4 files changed, 24 insertions, 1 deletions
@@ -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 @@ -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 |