C++ Mathematical Expression Library (ExprTk) https://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
c165d4864e
commit
3bd10f1ba6
|
@ -44,22 +44,22 @@ void newton_sqrt()
|
||||||
.add(
|
.add(
|
||||||
function_t( // define function: newton_sqrt(x)
|
function_t( // define function: newton_sqrt(x)
|
||||||
"newton_sqrt",
|
"newton_sqrt",
|
||||||
" switch "
|
" switch "
|
||||||
" { "
|
" { "
|
||||||
" case x < 0 : -inf; "
|
" case x < 0 : -inf; "
|
||||||
" case x == 0 : 0; "
|
" case x == 0 : 0; "
|
||||||
" case x == 1 : 1; "
|
" case x == 1 : 1; "
|
||||||
" default: "
|
" default: "
|
||||||
" ~{ "
|
" ~{ "
|
||||||
" var z := 100; "
|
" var z := 100; "
|
||||||
" var y := x / 2; "
|
" var sqrt_x := x / 2; "
|
||||||
" repeat "
|
" repeat "
|
||||||
" y := (1 / 2) * (y + (x / y)); "
|
" sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); "
|
||||||
" if (equal(y * y, x)) "
|
" if (equal(sqrt_x^2, x)) "
|
||||||
" break[y]; "
|
" break[sqrt_x]; "
|
||||||
" until ((z -= 1) <= 0); "
|
" until ((z -= 1) <= 0); "
|
||||||
" }; "
|
" }; "
|
||||||
" } ",
|
" } ",
|
||||||
"x"));
|
"x"));
|
||||||
|
|
||||||
std::string expression_str = "newton_sqrt(x)";
|
std::string expression_str = "newton_sqrt(x)";
|
||||||
|
|
30
readme.txt
30
readme.txt
|
@ -877,8 +877,8 @@ behaviours when using the expressions in various contexts such as
|
||||||
muli-threading et al.
|
muli-threading et al.
|
||||||
|
|
||||||
The prescribed method for cloning an expression is to compile it from
|
The prescribed method for cloning an expression is to compile it from
|
||||||
its string form. Doing so will allow the one to properly consider the
|
its string form. Doing so will allow the 'user' to properly consider
|
||||||
exact source of user defined variables and functions.
|
the exact source of user defined variables and functions.
|
||||||
|
|
||||||
Note: The exprtk::parser is a non-copyable and non-thread safe
|
Note: The exprtk::parser is a non-copyable and non-thread safe
|
||||||
component, and should only be shared via either a reference, a shared
|
component, and should only be shared via either a reference, a shared
|
||||||
|
@ -893,19 +893,19 @@ operations for compiling multiple expressions via the parser and
|
||||||
inserting the newly minted exprtk::expression instances into a
|
inserting the newly minted exprtk::expression instances into a
|
||||||
std::vector.
|
std::vector.
|
||||||
|
|
||||||
|
+----[exprtk::parser]---+
|
||||||
+--[exprtk::parser]--+
|
| Expression Factory |
|
||||||
| expression factory |
|
| parser_t::compile(...)|
|
||||||
+---->- compile(....) ->---+
|
+--> ~.~.~.~.~.~.~.~.~.~ ->--+
|
||||||
| +--------------------+ |
|
| +-----------------------+ |
|
||||||
Expressions | | Expressions as
|
Expressions in | | Expressions as
|
||||||
in string form A V exprtk::expression
|
string form A V exprtk::expression
|
||||||
| | instances
|
| | instances
|
||||||
[s0:'x+1']------+ | | +-[e0: x+1]
|
[s0:'x+1']--->--+ | | +-[e0: x+1]
|
||||||
| | | |
|
| | | |
|
||||||
[s1:'2z+y']-----+--+ +-->+-[e1: 2z+y]
|
[s1:'2z+y']-->--+--+ +->+-[e1: 2z+y]
|
||||||
| |
|
| |
|
||||||
[s2:'sin(k+w)']-+ +-[e2: sin(k+w)]
|
[s2:'sin(k+w)']-+ +-[e2: sin(k+w)]
|
||||||
|
|
||||||
|
|
||||||
const std::string expression_str[3]
|
const std::string expression_str[3]
|
||||||
|
|
Loading…
Reference in New Issue