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

This commit is contained in:
Arash Partow
2016-10-04 10:27:29 +11:00
parent 778726493b
commit 2634a0b0b4
2 changed files with 31 additions and 31 deletions

View File

@ -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)";