-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.h
93 lines (83 loc) · 2.92 KB
/
operations.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Created by boristab on 26.11.2019.
//
DEF_CMD(ADD, 1, "+", {
answer = diffAdd(node, answerTree, tex);
}, {
nodeToTex(node->leftChild, tex);
fprintf(tex, " + ");
nodeToTex(node->rightChild, tex);
})
DEF_CMD(SUB, 2, "-", {
answer = diffAdd(node, answerTree, tex);
}, {
nodeToTex(node->leftChild, tex);
fprintf(tex, " - ");
nodeToTex(node->rightChild, tex);
})
DEF_CMD(MUL, 3, "*", {
answer = diffMul(node, answerTree, tex);
}, {
if (node->leftChild->nodeType == NUMBER && node->leftChild->value == -1) {
fprintf(tex, " \\left(-");
nodeToTex(node->rightChild, tex);
fprintf(tex, "\\right) ");
} else {
if (node->leftChild->nodeType == MATH_OPERATION && node->leftChild->value < MUL) fprintf(tex, "\\left(");
nodeToTex(node->leftChild, tex);
if (node->leftChild->nodeType == MATH_OPERATION && node->leftChild->value < MUL) fprintf(tex, "\\right)");
fprintf(tex, " \\cdot ");
if (node->rightChild->nodeType == MATH_OPERATION && node->rightChild->value < MUL) fprintf(tex, "\\left(");
nodeToTex(node->rightChild, tex);
if (node->rightChild->nodeType == MATH_OPERATION && node->rightChild->value < MUL) fprintf(tex, "\\right)");
}
})
DEF_CMD(DIV, 4, "/", {
answer = diffDiv(node, answerTree, tex);
}, {
fprintf(tex, "\\frac{");
nodeToTex(node->leftChild, tex);
fprintf(tex, "}{");
nodeToTex(node->rightChild, tex);
fprintf(tex, "}");
})
DEF_CMD(DEG, 5, "^", {
answer = diffDeg(node, answerTree);
}, {
if (node->rightChild->nodeType == NUMBER && node->rightChild->value == 1) nodeToTex(node->leftChild, tex);
else {
if (node->leftChild->nodeType == MATH_OPERATION) fprintf(tex, "{ \\left(");
nodeToTex(node->leftChild, tex);
if (node->leftChild->nodeType == MATH_OPERATION) fprintf(tex, "\\right) }");
fprintf(tex, " ^ {");
nodeToTex(node->rightChild, tex);
fprintf(tex, "}");
}
})
DEF_CMD(SIN, 6, "sin", {
answer = diffSin(node, answerTree);
}, {
fprintf(tex, " \\sin{ ");
if (node->rightChild->nodeType == MATH_OPERATION) fprintf(tex, "\\left(");
nodeToTex(node->rightChild, tex);
if (node->rightChild->nodeType == MATH_OPERATION) fprintf(tex, "\\right)");
fprintf(tex, " } ");
})
DEF_CMD(COS, 7, "cos", {
answer = diffCos(node, answerTree);
}, {
fprintf(tex, " \\cos{ ");
if (node->rightChild->nodeType == MATH_OPERATION) fprintf(tex, "\\left(");
nodeToTex(node->rightChild, tex);
if (node->rightChild->nodeType == MATH_OPERATION) fprintf(tex, "\\right)");
fprintf(tex, " } ");
})
DEF_CMD(LN, 8, "ln", {
answer = diffLn(node, answerTree);
}, {
fprintf(tex, " \\ln{ ");
if (node->rightChild->nodeType == MATH_OPERATION) fprintf(tex, "\\left(");
nodeToTex(node->rightChild, tex);
if (node->rightChild->nodeType == MATH_OPERATION) fprintf(tex, "\\right)");
fprintf(tex, " } ");
})