-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgrad.c
49 lines (40 loc) · 775 Bytes
/
cgrad.c
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
#include <stdio.h>
typedef struct value_t {
float data;
struct value_t* left;
struct value_t* right;
char op;
} value_t;
void value_print(value_t v) {
printf("Value(data=%0.4f)\n", v.data);
}
value_t value_create(float data) {
return (value_t){
.data = data
};
}
value_t value_add(value_t a, value_t b) {
return (value_t){
.data = a.data + b.data,
.left = &a,
.right = &b,
.op = '+'
};
}
value_t value_mul(value_t a, value_t b) {
return (value_t){
.data = a.data * b.data,
.left = &a,
.right = &b,
.op = '*'
};
}
int main() {
value_t a = value_create(3.0);
value_t b = value_create(-4.0);
value_t c = value_add(a, b);
value_print(c);
value_t d = value_mul(c, b);
value_print(d);
return 0;
}