C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html

This commit is contained in:
Arash Partow 2014-01-05 19:49:26 +11:00
parent 953f3aeaad
commit fd75022a4a
3 changed files with 530 additions and 143 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1002,7 +1002,8 @@ static const test_t test_list[] =
test_t("repeat 1.1234; 1 < 2; 1.1 + 2.2 until (1 < 2)",3.3),
test_t("repeat 1.1234; 1 < 2; (1.1 + 2.2) until (1 < 2)",3.3),
test_t("repeat 1.1234; 1 < 2; 1.1 + 2.2; until (1 < 2)",3.3),
test_t("repeat 1.1234; 1 < 2; (1.1 + 2.2); until (1 < 2)",3.3)
test_t("repeat 1.1234; 1 < 2; (1.1 + 2.2); until (1 < 2)",3.3),
test_t("[*] { case 1 < 2 : 1 / 2; case (1 < 3) : 2 / 2; case 1 < 4 : 3 / 2; case (1 < 5) : 4 / 2; }",2.0)
};
static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_t);
@ -1113,6 +1114,7 @@ inline bool run_test00()
}
}
}
return true;
}
@ -1315,7 +1317,10 @@ inline bool run_test01()
test_xy<T>("switch { case {x <= y} : switch { case {x <= y} : x; default: 1.12345; }; default: 1.12345; }",T(1.0),T(2.0),T(1.0)),
test_xy<T>("switch { case [(x <= y)] : {y - x}; default: 1.12345; }",T(1.0),T(2.0),T(1.0)),
test_xy<T>("switch { case ([x > y]) : [0]; case ([x <= y]) : [y - x]; default: 1.12345; }",T(1.0),T(2.0),T(1.0)),
test_xy<T>("switch { case {(x <= y)} : switch { case ({x <= y}) : x; default: 1.12345; }; default: 1.12345; }",T(1.0),T(2.0),T(1.0))
test_xy<T>("switch { case {(x <= y)} : switch { case ({x <= y}) : x; default: 1.12345; }; default: 1.12345; }",T(1.0),T(2.0),T(1.0)),
test_xy<T>("[*]{ case x < y : x + y; case y < x : y - x; }",T(2.0),T(3.0),T(5.0)),
test_xy<T>("[*]{ case x > y : x + y; case y > x : y - x; }",T(2.0),T(3.0),T(1.0)),
test_xy<T>("[*]{ case x > y : x - y; case y < x : y + x; }",T(2.0),T(3.0),T(0.0))
};
static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_xy<T>);
@ -3098,6 +3103,7 @@ inline std::size_t load_expressions(const std::string& file_name,
++line_count;
sequence.push_back(buffer);
}
return line_count;
}

View File

@ -392,6 +392,17 @@ include path (e.g: /usr/include/).
| | ~(i := x + 1, j := y / z, k := sin(w/u)) == (sin(w/u))) |
| | ~{i := x + 1; j := y / z; k := sin(w/u)} == (sin(w/u))) |
+----------+---------------------------------------------------------+
| [*] | Evaluate any consequent for which its case statement is |
| | true. The return value will be either zero or the result|
| | of the last consequent to have been evaluated. |
| | eg: |
| | [*] |
| | { |
| | case (x + 1) > (y - 2) : x := z / 2 + sin(y / pi); |
| | case (x + 2) < abs(y + 3): w / 4 + min(5y,9); |
| | case (x + 3) = (y * 4) : y := abs(z / 6) + 7y; |
| | } |
+----------+---------------------------------------------------------+
@ -434,10 +445,13 @@ Expression: z := (x + y^-2.345) * sin(pi / min(w - 7.3,v))
______/ \______ Constant(pi) [Binary-Func(min)]
/ \ ___/ \___
Variable(y) [Negate] / \
| [Subtract] Variable(v)
Constant(2.345) ____/ \___
/ \
Variable(w) Constant(7.3)
| / Variable(v)
Constant(2.345) /
/
[Subtract]
____/ \___
/ \
Variable(w) Constant(7.3)
(3) Parser
A structure which takes as input a string representation of an
@ -565,7 +579,7 @@ correctly optimize such expressions for a given architecture.
(12) Strings may be constructed from any letters, digits or special
characters such as (~!@#$%^&*()[]|=+ ,./?<>;:"`~_), and must
be enclosed with single-quotes.
eg: 'Frankly, my dear, I do not give a damn!'
eg: 'Frankly my dear, I do not give a damn!'
(13) User defined normal functions can have up to 20 parameters,
where as user defined vararg-functions can have an unlimited