OpcUaCanOpen
CANopen OPC-UA server
exprtk_simple_example_01.cpp
Go to the documentation of this file.
1
/*
2
**************************************************************
3
* C++ Mathematical Expression Toolkit Library *
4
* *
5
* Simple Example 1 *
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>
26
void
trig_function
()
27
{
28
typedef
exprtk::symbol_table<T>
symbol_table_t
;
29
typedef
exprtk::expression<T>
expression_t
;
30
typedef
exprtk::parser<T>
parser_t
;
31
32
std::string
expression_string =
"clamp(-1.0,sin(2 * pi * x) + cos(x / 2 * pi),+1.0)"
;
33
34
T
x
;
35
36
symbol_table_t
symbol_table;
37
symbol_table.
add_variable
(
"x"
,
x
);
38
symbol_table.add_constants();
39
40
expression_t
expression;
41
expression.
register_symbol_table
(symbol_table);
42
43
parser_t
parser
;
44
parser
.compile(expression_string,expression);
45
46
for
(
x
= T(-5);
x
<= T(+5);
x
+= T(0.001))
47
{
48
T y = expression.value();
49
printf(
"%19.15f\t%19.15f\n"
,
x
,y);
50
}
51
}
52
53
int
main
()
54
{
55
trig_function<double>();
56
return
0;
57
}
exprtk
exprtk_simple_example_01.cpp
Generated on Fri Sep 11 2020 14:30:03 for OpcUaCanOpen by
1.8.14