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

This commit is contained in:
Arash Partow 2017-02-14 20:24:11 +11:00
parent b37321d094
commit 1bb3d0e5df
3 changed files with 33 additions and 22 deletions

View File

@ -2441,7 +2441,7 @@ namespace exprtk
if ( if (
(s_itr_ != initial_itr) && (s_itr_ != initial_itr) &&
!is_end(s_itr_ + 1) && !is_end(s_itr_ + 1) &&
details::is_letter_or_digit(*(s_itr_ + 1)) && !details::is_letter_or_digit(*(s_itr_ + 1)) &&
('_' != (*(s_itr_ + 1))) ('_' != (*(s_itr_ + 1)))
) )
break; break;
@ -2459,21 +2459,23 @@ namespace exprtk
{ {
/* /*
Attempt to match a valid numeric value in one of the following formats: Attempt to match a valid numeric value in one of the following formats:
01. 123456 (01) 123456
02. 123.456 (02) 123456.
03. 123.456e3 (03) 123.456
04. 123.456E3 (04) 123.456e3
05. 123.456e+3 (05) 123.456E3
06. 123.456E+3 (06) 123.456e+3
07. 123.456e-3 (07) 123.456E+3
08. 123.456E-3 (08) 123.456e-3
09. .1234 (09) 123.456E-3
10. .1234e3 (00) .1234
11. .1234E+3 (11) .1234e3
12. .1234e+3 (12) .1234E+3
13. .1234E-3 (13) .1234e+3
14. .1234e-3 (14) .1234E-3
(15) .1234e-3
*/ */
const char* initial_itr = s_itr_; const char* initial_itr = s_itr_;
bool dot_found = false; bool dot_found = false;
bool e_found = false; bool e_found = false;

View File

@ -332,6 +332,11 @@ static const test_t global_test_list[] =
test_t("7-2",+5.0), test_t("7-2",+5.0),
test_t("8-1",+7.0), test_t("8-1",+7.0),
test_t("9-0",+9.0), test_t("9-0",+9.0),
test_t("2.*3",+6.0),
test_t("2.*3.",+6.0),
test_t("2.+3",+5.0),
test_t("2.+3.",+5.0),
test_t("123.*456.",+56088.0),
test_t(" 0 - 9 ",-9.0), test_t(" 0 - 9 ",-9.0),
test_t(" 1 - 8 ",-7.0), test_t(" 1 - 8 ",-7.0),
test_t(" 2 - 7 ",-5.0), test_t(" 2 - 7 ",-5.0),
@ -1596,7 +1601,11 @@ inline bool run_test01()
test_xy<T>("var a := 2; (a / 1) == a",T(0),T(0),T(1)), test_xy<T>("var a := 2; (a / 1) == a",T(0),T(0),T(1)),
test_xy<T>("var a := 2; (0 + a) == a",T(0),T(0),T(1)), test_xy<T>("var a := 2; (0 + a) == a",T(0),T(0),T(1)),
test_xy<T>("var a := 2; (a + 0) == a",T(0),T(0),T(1)), test_xy<T>("var a := 2; (a + 0) == a",T(0),T(0),T(1)),
test_xy<T>("var a := 2; (1 * a) == a",T(0),T(0),T(1)) test_xy<T>("var a := 2; (1 * a) == a",T(0),T(0),T(1)),
test_xy<T>("var a.b := 3; (2 * a.b ) == 6",T(0),T(0),T(1)),
test_xy<T>("var aa.bb := 3; (2 * aa.bb ) == 6",T(0),T(0),T(1)),
test_xy<T>("var aaa.bbb := 3; (2 * aaa.bbb) == 6",T(0),T(0),T(1)),
test_xy<T>("var a1.b2 := 3; (2 * a1.b2 ) == 6",T(0),T(0),T(1))
}; };
static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_xy<T>); static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_xy<T>);

View File

@ -853,7 +853,7 @@ Generally an expression in ExprTk can be thought of as a free function
similar to those found in imperative languages. This form of pseudo similar to those found in imperative languages. This form of pseudo
function will have a name, it may have a set of one or more inputs and function will have a name, it may have a set of one or more inputs and
will return at least one value as its result. Futhermore the function will return at least one value as its result. Futhermore the function
when invoked, may cause a side-effect that changes the state the of when invoked, may cause a side-effect that changes the state of the
host program. host program.
As an example the following is a pseudo-code definition of a free As an example the following is a pseudo-code definition of a free
@ -1318,8 +1318,8 @@ in the expression and hence will be assumed to have a side-effect.
During compilation when the DCE optimisation is applied to the above During compilation when the DCE optimisation is applied to the above
expression, statement 2 will be removed from the expression, as it has expression, statement 2 will be removed from the expression, as it has
no bearing on the final result of expression, the rest of the no bearing on the final result of expression, the rest of the
statements will all remain. Hence optimised version of the expression statements will all remain. The optimised form of the expression is as
is as follows: follows:
var x := 2; // Statement 1 var x := 2; // Statement 1
var y := x + 2; // Statement 2 var y := x + 2; // Statement 2
@ -1341,7 +1341,7 @@ In the example above, if the condition 'y < z' is true, then the
consequent 'y + 1' will be evaluated, its value will be returned and consequent 'y + 1' will be evaluated, its value will be returned and
subsequently assigned to the variable 'x'. Otherwise the alternative subsequently assigned to the variable 'x'. Otherwise the alternative
'2 * z' will be evaluated and its value will be returned. This is '2 * z' will be evaluated and its value will be returned. This is
essentially the simplest form of an if-then-else statement, As simple essentially the simplest form of an if-then-else statement. A simple
variation of the expression where the value of the if-statement is variation of the expression where the value of the if-statement is
used within another statement is as follows: used within another statement is as follows: