use of org.matheclipse.core.eval.interfaces.INumeric in project symja_android_library by axkr.
the class DoubleStackEvaluator method evalAST.
public static double evalAST(double[] stack, final int top, final IAST ast) {
final ISymbol symbol = (ISymbol) ast.get(0);
if (symbol.isBuiltInSymbol()) {
final IEvaluator module = ((IBuiltInSymbol) symbol).getEvaluator();
if (module instanceof INumeric) {
int newTop = top;
// fast evaluation path
if (top + ast.size() >= stack.length) {
stack = new double[ast.size() + 50];
}
for (int i = 1; i < ast.size(); i++) {
++newTop;
stack[newTop] = DoubleStackEvaluator.eval(stack, newTop, ast.get(i));
}
return ((INumeric) module).evalReal(stack, newTop, ast.size() - 1);
}
}
// slow evaluation path
final IExpr result = F.evaln(ast);
if (result instanceof Num) {
return ((Num) result).doubleValue();
}
throw new UnsupportedOperationException("EvalDouble#evalAST(): " + ast);
}
Aggregations