本文整理汇总了C#中Expression.calculate方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.calculate方法的具体用法?C# Expression.calculate怎么用?C# Expression.calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression.calculate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testScenario
protected override void testScenario()
{
Expression e = new Expression("");
for (int i = 0; i <= base.iterNum; i++)
e = new Expression("sin(2+(3*4)^2)/10");
e.calculate();
}
示例2: forwardDifference
/**
* Forward difference(h) operator (at the current value of the argument x)
*
* @param f the expression
* @param h the difference
* @param x the argument name
*
* @return Forward difference(h) value calculated at at the current value of the argument x.
*
* @see Expression
* @see Argument
*/
public static double forwardDifference(Expression f, double h, Argument x)
{
double xb = x.getArgumentValue();
if (Double.IsNaN(xb))
return Double.NaN;
double fv = f.calculate();
x.setArgumentValue(xb + h);
double delta = f.calculate() - fv;
x.setArgumentValue(xb);
return delta;
}
示例3: Start
//.........这里部分代码省略.........
n3 = e.getFunctionsNumber();
syn3 = e.checkSyntax();
e.removeFunctions(f3);
n4 = e.getFunctionsNumber();
e.removeFunctions(f6,f7);
syn4 = e.getSyntaxStatus();
n5 = e.getFunctionsNumber();
syn5 = e.checkSyntax();
e.removeAllFunctions();
n6 = e.getFunctionsNumber();
syn6 = e.getSyntaxStatus();
if ( n2 == n1
&& n2-n3 == 2
&& n3-n4 == 1
&& n4-n5 == 2
&& n6 == 0
&& syn1 == Expression.NO_SYNTAX_ERRORS
&& syn2 == Expression.SYNTAX_ERROR_OR_STATUS_UNKNOWN
&& syn3 == Expression.NO_SYNTAX_ERRORS
&& syn4 == Expression.SYNTAX_ERROR_OR_STATUS_UNKNOWN
&& syn5 == Expression.NO_SYNTAX_ERRORS
&& syn6 == Expression.SYNTAX_ERROR_OR_STATUS_UNKNOWN
)
test[testId] = true;
/*
* 20.
* double calculate()
* String getHelp()
* String getHelp(String word)
* String getLicense()
*/
testId++;
syn1 = e.checkSyntax();
d1 = e.calculate();
syn2 = e.getSyntaxStatus();
if ( syn1 == Expression.NO_SYNTAX_ERRORS
&& syn2 == Expression.NO_SYNTAX_ERRORS
&& d1 == 3)
test[testId] = true;
/*
* 21. Tokens
*/
testId++;
e = new Expression("1+(2+3)-sin(10)");
List<Token> tokens = e.getCopyOfInitialTokens();
mXparser.consolePrintTokens(tokens);
if (
(tokens[0].tokenStr.Equals("1")) &&
(tokens[1].tokenStr.Equals("+")) &&
(tokens[2].tokenStr.Equals("(")) &&
(tokens[3].tokenStr.Equals("2")) &&
(tokens[4].tokenStr.Equals("+")) &&
(tokens[5].tokenStr.Equals("3")) &&
(tokens[6].tokenStr.Equals(")")) &&
(tokens[7].tokenStr.Equals("-")) &&
(tokens[8].tokenStr.Equals("sin")) &&
(tokens[9].tokenStr.Equals("(")) &&
(tokens[10].tokenStr.Equals("10")) &&
(tokens[11].tokenStr.Equals(")")) &&
(tokens[0].tokenTypeId == ParserSymbol.NUMBER_TYPE_ID) &&
(tokens[1].tokenTypeId == Operator.TYPE_ID) &&
(tokens[2].tokenTypeId == ParserSymbol.TYPE_ID) &&
(tokens[3].tokenTypeId == ParserSymbol.NUMBER_TYPE_ID) &&
(tokens[4].tokenTypeId == Operator.TYPE_ID) &&
示例4: runTest
//.........这里部分代码省略.........
e = new Expression("x", x);
exp[testId] = e;
reg = false;
syn = e.checkSyntax();
if (msg.IndexOf("Invalid argument definition") >= 0)
testResult = true;
mXparser.consolePrint(syn + " reg ... " + reg + " --> " + " -----> " + msg);
break;
case 96:
expStr = "x(a, b, c,)=a+c";
mXparser.consolePrint(expStr + " ...... ");
x = new Argument(expStr);
msg = x.getErrorMessage();
e = new Expression("x", x);
exp[testId] = e;
reg = false;
syn = e.checkSyntax();
if (msg.IndexOf("Invalid argument definition") >= 0)
testResult = true;
mXparser.consolePrint(syn + " reg ... " + reg + " --> " + " -----> " + msg);
break;
case 97:
expStr = " x ( a, b , c ) = a+b+c";
mXparser.consolePrint(expStr + " ...... ");
x = new Argument(expStr, new Argument("a = 1"), new Argument("b = 2"), new Argument(" c = 3"));
msg = x.getErrorMessage();
e = new Expression("x", x);
exp[testId] = e;
reg = true;
syn = e.checkSyntax();
if (
(msg.IndexOf("Invalid argument definition") == -1) &&
(reg == syn) &&
(e.calculate() == 6)
)
testResult = true;
mXparser.consolePrint(syn + " reg ... " + reg + " --> " + " -----> " + e.calculate() + " " + msg);
break;
case 98:
expStr = "x 5";
mXparser.consolePrint(expStr + " ...... ");
x = new Argument(expStr);
msg = x.getErrorMessage();
e = new Expression("x", x);
exp[testId] = e;
reg = false;
syn = e.checkSyntax();
if (msg.IndexOf("Invalid argument definition") >= 0)
testResult = true;
mXparser.consolePrint(syn + " reg ... " + reg + " --> " + " -----> " + msg);
break;
case 99:
expStr = " x = 5 + 1 + 2";
mXparser.consolePrint(expStr + " ...... ");
x = new Argument(expStr, new Argument("a = 1"), new Argument("b = 2"), new Argument(" c = 3"));
msg = x.getErrorMessage();
e = new Expression("x", x);
exp[testId] = e;
reg = true;
syn = e.checkSyntax();
if (
(msg.IndexOf("Invalid argument definition") == -1) &&
(reg == syn) &&
(e.calculate() == 8)
)
testResult = true;