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

Go to the source code of this file.

Functions

template<typename T >
void trig_function ()
 
int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 55 of file exprtk_simple_example_01.cpp.

56{
57 trig_function<double>();
58 return 0;
59}

◆ trig_function()

template<typename T >
void trig_function ( )

Definition at line 27 of file exprtk_simple_example_01.cpp.

28{
29 typedef exprtk::symbol_table<T> symbol_table_t;
30 typedef exprtk::expression<T> expression_t;
31 typedef exprtk::parser<T> parser_t;
32
33 const std::string expression_string =
34 "clamp(-1.0, sin(2 * pi * x) + cos(x / 2 * pi), +1.0)";
35
36 T x;
37
38 symbol_table_t symbol_table;
39 symbol_table.add_variable("x",x);
40 symbol_table.add_constants();
41
42 expression_t expression;
43 expression.register_symbol_table(symbol_table);
44
45 parser_t parser;
46 parser.compile(expression_string,expression);
47
48 for (x = T(-5); x <= T(+5); x += T(0.001))
49 {
50 const T y = expression.value();
51 printf("%19.15f\t%19.15f\n", x, y);
52 }
53}
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:24443

References exprtk::parser< T >::compile().

Here is the call graph for this function: