OpcUaCanOpen
CANopen OPC-UA server
exprtk_simple_example_14.cpp
Go to the documentation of this file.
1 /*
2  **************************************************************
3  * C++ Mathematical Expression Toolkit Library *
4  * *
5  * Simple Example 14 *
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 {
30 
31  std::string stddev_program =
32  " var x[25] := { "
33  " 1, 2, 3, 4, 5, "
34  " 6, 7, 8, 9, 10, "
35  " 11, 12, 13, 14, 15, "
36  " 16, 17, 18, 19, 20, "
37  " 21, 22, 23, 24, 25 "
38  " }; "
39  " "
40  " sqrt(sum([x - avg(x)]^2) / x[]) ";
41 
42  expression_t expression;
43 
45  parser.compile(stddev_program,expression);
46 
47  T stddev = expression.value();
48 
49  printf("stddev(1..25) = %10.6f\n",stddev);
50 }
51 
52 int main()
53 {
54  stddev_example<double>();
55  return 0;
56 }