-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathNodesTest.cpp
More file actions
47 lines (34 loc) · 769 Bytes
/
MathNodesTest.cpp
File metadata and controls
47 lines (34 loc) · 769 Bytes
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
//MathNodesTest.cpp
#include "MathNodes.hpp"
#include "MathTreeBuilder.hpp"
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define MAX_BUFFER_SIZE 128
float exit_func();
int main(int argc, char **args){
char temp[MAX_BUFFER_SIZE];
float pi = 3.14159265359f;
MathTreeBuilder mtb;
MathNode *mn;
mtb.addVariable(&pi, "pi");
mtb.addFunction(exit_func,"exit");
//addFunction is overloaded to handle both:
// float (*func)()
// float (*func)(float)
mtb.addFunction(sinf,"sin");
mtb.addFunction(cosf,"cos");
mtb.addFunction(tanf,"tan");
while(true){
printf("expression : ");
gets_s(temp);
mn = mtb.parse(temp);
printf("\t%f\n\n", mn->getValue());
delete mn;
}
return 0;
}
float exit_func(){
exit(0);
return 0.f;
}