.examples

git-svn-id: svn://ultimatepp.org/upp/trunk@11719 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-01-23 08:57:03 +00:00
parent 4bdb2162d2
commit 117d43a4af

View file

@ -57,6 +57,8 @@ double ExpressionEvaluator::Factor()
return fabs(Factor());
if(p.Id("sqrt"))
return sqrt(Factor());
if(p.Id("exp"))
return exp(Factor());
if(p.Id("ln"))
return log(Factor());
if(p.Id("log"))
@ -93,12 +95,26 @@ double ExpressionEvaluator::Factor()
return M_E;
if(p.Id("pi")) // pi constant
return M_PI;
double x;
if(p.Char('(')) { // resolve parenthesis - recurse back to Sum (+ - operators)
double y = Expression();
x = Expression();
p.PassChar(')'); // make sure there is closing parenthesis
return y;
}
return p.ReadDouble(); // last possibility is that we are at number...
else
x = p.ReadDouble(); // last possibility is that we are at number...
if(p.Char('!')) { // compute factorial
if(x >= 0 && x < 120) {
int n = (int)x;
if(n == x) {
x = 1;
for(int q = 1; q <= n; q++)
x *= q;
return x;
}
}
p.ThrowError("invalid argument");
}
return x;
}
double Evaluate(const char *s, double x)