diff --git a/exprtk_simple_example_10.cpp b/exprtk_simple_example_10.cpp index 48f2078..3e1dbe8 100644 --- a/exprtk_simple_example_10.cpp +++ b/exprtk_simple_example_10.cpp @@ -44,22 +44,22 @@ void newton_sqrt() .add( function_t( // define function: newton_sqrt(x) "newton_sqrt", - " switch " - " { " - " case x < 0 : -inf; " - " case x == 0 : 0; " - " case x == 1 : 1; " - " default: " - " ~{ " - " var z := 100; " - " var y := x / 2; " - " repeat " - " y := (1 / 2) * (y + (x / y)); " - " if (equal(y * y, x)) " - " break[y]; " - " until ((z -= 1) <= 0); " - " }; " - " } ", + " switch " + " { " + " case x < 0 : -inf; " + " case x == 0 : 0; " + " case x == 1 : 1; " + " default: " + " ~{ " + " var z := 100; " + " var sqrt_x := x / 2; " + " repeat " + " sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); " + " if (equal(sqrt_x^2, x)) " + " break[sqrt_x]; " + " until ((z -= 1) <= 0); " + " }; " + " } ", "x")); std::string expression_str = "newton_sqrt(x)"; diff --git a/readme.txt b/readme.txt index 3686f5d..6133c44 100644 --- a/readme.txt +++ b/readme.txt @@ -877,8 +877,8 @@ behaviours when using the expressions in various contexts such as muli-threading et al. 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 -exact source of user defined variables and functions. +its string form. Doing so will allow the 'user' to properly consider +the exact source of user defined variables and functions. Note: The exprtk::parser is a non-copyable and non-thread safe 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 std::vector. - - +--[exprtk::parser]--+ - | expression factory | - +---->- compile(....) ->---+ - | +--------------------+ | - Expressions | | Expressions as - in string form A V exprtk::expression - | | instances - [s0:'x+1']------+ | | +-[e0: x+1] - | | | | - [s1:'2z+y']-----+--+ +-->+-[e1: 2z+y] - | | - [s2:'sin(k+w)']-+ +-[e2: sin(k+w)] + +----[exprtk::parser]---+ + | Expression Factory | + | parser_t::compile(...)| + +--> ~.~.~.~.~.~.~.~.~.~ ->--+ + | +-----------------------+ | + Expressions in | | Expressions as + string form A V exprtk::expression + | | instances + [s0:'x+1']--->--+ | | +-[e0: x+1] + | | | | + [s1:'2z+y']-->--+--+ +->+-[e1: 2z+y] + | | + [s2:'sin(k+w)']-+ +-[e2: sin(k+w)] const std::string expression_str[3]