1 // Simple example file for the function parser
\r
2 // ===========================================
\r
4 /* When running the program, try for example with these values:
\r
13 #include "../fparser.hh"
\r
20 std::string function;
\r
21 double minx, maxx, step;
\r
22 FunctionParser fparser;
\r
24 fparser.AddConstant("pi", 3.1415926535897932);
\r
28 std::cout << "f(x) = ";
\r
29 std::getline(std::cin, function);
\r
30 if(std::cin.fail()) return 0;
\r
32 int res = fparser.Parse(function, "x");
\r
35 std::cout << std::string(res+7, ' ') << "^\n"
\r
36 << fparser.ErrorMsg() << "\n\n";
\r
39 std::cout << "min x: ";
\r
41 std::cout << "max x: ";
\r
43 std::cout << "step: ";
\r
45 if(std::cin.fail()) return 0;
\r
47 double vals[] = { 0 };
\r
48 for(vals[0] = minx; vals[0] <= maxx; vals[0] += step)
\r
50 std::cout << "f(" << vals[0] << ") = " << fparser.Eval(vals)
\r