C++ Mathematical Expression Toolkit (ExprTk)
release
Toggle main menu visibility
Loading...
Searching...
No Matches
exprtk
exprtk_simple_example_01.cpp
Go to the documentation of this file.
1
/*
2
**************************************************************
3
* C++ Mathematical Expression Toolkit Library *
4
* *
5
* Simple Example 01 *
6
* Author: Arash Partow (1999-2025) *
7
* URL: https://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
* https://www.opensource.org/licenses/MIT *
14
* SPDX-License-Identifier: MIT *
15
* *
16
**************************************************************
17
*/
18
19
20
#include <cstdio>
21
#include <string>
22
23
#include "
exprtk.hpp
"
24
25
26
template
<
typename
T>
27
void
trig_function
()
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
}
54
55
int
main
()
56
{
57
trig_function<double>
();
58
return
0;
59
}
exprtk::expression
Definition
exprtk.hpp:21832
exprtk::parser
Definition
exprtk.hpp:22525
exprtk::parser::compile
bool compile(const std::string &expression_string, expression< T > &expr)
Definition
exprtk.hpp:24826
exprtk::symbol_table
Definition
exprtk.hpp:20090
exprtk.hpp
trig_function
void trig_function()
Definition
exprtk_simple_example_01.cpp:27
main
int main()
Definition
exprtk_simple_example_01.cpp:55
Generated by
1.17.0