Search in sources :

Example 6 with Num

use of org.matheclipse.core.expression.Num 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

Num (org.matheclipse.core.expression.Num)6 IExpr (org.matheclipse.core.interfaces.IExpr)6 ISymbol (org.matheclipse.core.interfaces.ISymbol)5 ComplexNum (org.matheclipse.core.expression.ComplexNum)3 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)3 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 INum (org.matheclipse.core.interfaces.INum)3 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)3 EvalEngine (org.matheclipse.core.eval.EvalEngine)2 IRational (org.matheclipse.core.interfaces.IRational)2 INumeric (org.matheclipse.core.eval.interfaces.INumeric)1 INumericComplex (org.matheclipse.core.eval.interfaces.INumericComplex)1 INumericComplexConstant (org.matheclipse.core.eval.interfaces.INumericComplexConstant)1 ApcomplexNum (org.matheclipse.core.expression.ApcomplexNum)1 ApfloatNum (org.matheclipse.core.expression.ApfloatNum)1 IAST (org.matheclipse.core.interfaces.IAST)1 IComplex (org.matheclipse.core.interfaces.IComplex)1 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)1 IFraction (org.matheclipse.core.interfaces.IFraction)1