OpcUaCanOpen
CANopen OPC-UA server
exprtk_simple_example_06.cpp
Go to the documentation of this file.
1 /*
2  **************************************************************
3  * C++ Mathematical Expression Toolkit Library *
4  * *
5  * Simple Example 6 *
6  * Author: Arash Partow (1999-2019) *
7  * URL: http://www.partow.net/programming/exprtk/index.html *
8  * *
9  * Copyright notice: *
10  * Free use of the Mathematical Expression Toolkit Library is *
11  * permitted under the guidelines and in accordance with the *
12  * most current version of the MIT License. *
13  * http://www.opensource.org/licenses/MIT *
14  * *
15  **************************************************************
16 */
17 
18 
19 #include <cstdio>
20 #include <string>
21 
22 #include "exprtk.hpp"
23 
24 
25 template <typename T>
27 {
31 
32  std::string expression_string =
33  " for (var i := 0; i < min(x[],y[],z[]); i += 1) "
34  " { "
35  " z[i] := 3sin(x[i]) + 2log(y[i]); "
36  " } ";
37 
38  T x[] = { T(1.1), T(2.2), T(3.3), T(4.4), T(5.5) };
39  T y[] = { T(1.1), T(2.2), T(3.3), T(4.4), T(5.5) };
40  T z[] = { T(0.0), T(0.0), T(0.0), T(0.0), T(0.0) };
41 
42  symbol_table_t symbol_table;
43  symbol_table.add_vector("x",x);
44  symbol_table.add_vector("y",y);
45  symbol_table.add_vector("z",z);
46 
47  expression_t expression;
48  expression.register_symbol_table(symbol_table);
49 
51  parser.compile(expression_string,expression);
52 
53  expression.value();
54 }
55 
56 int main()
57 {
58  vector_function<double>();
59  return 0;
60 }