-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator.c
More file actions
65 lines (51 loc) · 1.08 KB
/
operator.c
File metadata and controls
65 lines (51 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "operator.h"
#include <stdlib.h>
#include <math.h>
double sum(double* args){
return args[1] + args[0];
}
double diff(double* args){
return args[1] - args[0];
}
double mult(double* args){
return args[1] * args[0];
}
double my_div(double* args){
return args[1] / args[0];
}
double my_sqrt(double* args){
return sqrt(args[0]);
}
double sqr(double* args){
return args[0] * args[0];
}
double my_pow(double* args){
return pow(args[1], args[0]);
}
double sum2(double* args){
return args[1] + args[0];
}
double fact_rec(double a)
{
if(a <= 0)
return 1;
else
return a * fact_rec(a-1);
}
double fact(double* args){
return fact_rec(args[0]);
}
Operator* newOperator(int priority, int arity, double (*function)(double*), notation_type notation, direction_type assoc)
{
Operator* new = malloc(sizeof(*new));
new -> priority = priority;
new -> arity = arity;
new -> function = function;
new -> notation = notation;
new -> assoc = assoc;
return new;
}
void deleteOperator(Operator* op)
{
free(op);
}