C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Classes | Functions
exprtk_simple_example_05.cpp File Reference
#include <cstdio>
#include <string>
#include "exprtk.hpp"
Include dependency graph for exprtk_simple_example_05.cpp:

Go to the source code of this file.

Classes

struct  myfunc< T >
 

Functions

template<typename T >
myotherfunc (T v0, T v1, T v2)
 
template<typename T >
void custom_function ()
 
int main ()
 

Function Documentation

◆ custom_function()

template<typename T >
void custom_function ( )

Definition at line 48 of file exprtk_simple_example_05.cpp.

49{
50 typedef exprtk::symbol_table<T> symbol_table_t;
51 typedef exprtk::expression<T> expression_t;
52 typedef exprtk::parser<T> parser_t;
53
54 const std::string expression_string =
55 "myfunc(sin(x / pi), otherfunc(3 * y, x / 2, x * y))";
56
57 T x = T(1);
58 T y = T(2);
59 myfunc<T> mf;
60
61 symbol_table_t symbol_table;
62 symbol_table.add_variable("x",x);
63 symbol_table.add_variable("y",y);
64 symbol_table.add_function("myfunc",mf);
65 symbol_table.add_function("otherfunc",myotherfunc);
66 symbol_table.add_constants();
67
68 expression_t expression;
69 expression.register_symbol_table(symbol_table);
70
71 parser_t parser;
72 parser.compile(expression_string,expression);
73
74 const T result = expression.value();
75 printf("Result: %10.5f\n",result);
76}
T myotherfunc(T v0, T v1, T v2)

References myotherfunc().

Here is the call graph for this function:

◆ main()

int main ( )

Definition at line 78 of file exprtk_simple_example_05.cpp.

79{
80 custom_function<double>();
81 return 0;
82}

◆ myotherfunc()

template<typename T >
T myotherfunc ( v0,
v1,
v2 
)

Definition at line 42 of file exprtk_simple_example_05.cpp.

43{
44 return std::abs(v0 - v1) * v2;
45}

Referenced by custom_function().

Here is the caller graph for this function: