Search in sources :

Example 1 with INumeric

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);
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) ISymbol(org.matheclipse.core.interfaces.ISymbol) INumeric(org.matheclipse.core.eval.interfaces.INumeric) Num(org.matheclipse.core.expression.Num) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

INumeric (org.matheclipse.core.eval.interfaces.INumeric)1 Num (org.matheclipse.core.expression.Num)1 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)1 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1