summaryrefslogtreecommitdiff
path: root/inverse.c
blob: c20e78deeee668fe70e542f3d321f798bfa020be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <u.h>
#include <libc.h>
#include <bio.h>

#include "apl9.h"

Function
inverse(Function f)
{
	/* TODO figure out a good way to structure this code */
	if(f.type == FunctypeOp && f.operator.type == OperatortypePrim && f.operator.code == 9 && f.operator.dyadic){
		/* obverse */
		Function newf = f;
		newf.operator.left = f.operator.right;
		newf.operator.right = f.operator.left;
		return newf;
	}

	Rune *msg = runesmprint("No inverse defined for %S", ppfunction(f));
	throwerror(msg, EDomain);
	return f;
}