C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
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-2024) *
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
26template <typename T>
28{
29 typedef exprtk::expression<T> expression_t;
30 typedef exprtk::parser<T> parser_t;
31
32 const std::string stddev_program =
33 " var x[25] := { "
34 " 1, 2, 3, 4, 5, "
35 " 6, 7, 8, 9, 10, "
36 " 11, 12, 13, 14, 15, "
37 " 16, 17, 18, 19, 20, "
38 " 21, 22, 23, 24, 25 "
39 " }; "
40 " "
41 " sqrt(sum([x - avg(x)]^2) / x[]) ";
42
43 expression_t expression;
44
45 parser_t parser;
46 parser.compile(stddev_program,expression);
47
48 const T stddev = expression.value();
49
50 printf("stddev(1..25) = %10.6f\n",stddev);
51}
52
53int main()
54{
55 stddev_example<double>();
56 return 0;
57}
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:24443
void stddev_example()