Search in sources :

Example 1 with INumericComplex

use of org.matheclipse.core.eval.interfaces.INumericComplex in project symja_android_library by axkr.

the class EvalComplex method evalAST.

public static double[] evalAST(final DoubleStack stack, final int top, final IAST ast) {
    final int newTop = top;
    final ISymbol symbol = (ISymbol) ast.get(0);
    if (symbol.isBuiltInSymbol()) {
        final IEvaluator module = ((IBuiltInSymbol) symbol).getEvaluator();
        if (module instanceof INumericComplex) {
            // fast evaluation path
            stack.ensureCapacity(top + ast.size() * 2);
            for (int i = 1; i < ast.size(); i++) {
                final double[] result = eval(stack, newTop, ast.get(i));
                stack.push(result[0]);
                stack.push(result[1]);
            }
            return ((INumericComplex) module).evalComplex(stack, ast.size() - 1);
        }
    }
    // slow evaluation path
    final IExpr result = F.evaln(ast);
    if (result instanceof ComplexNum) {
        final double[] res = new double[2];
        res[0] = ((ComplexNum) result).getRealPart();
        res[1] = ((ComplexNum) result).getImaginaryPart();
        return res;
    }
    if (result instanceof Num) {
        final double[] res = new double[2];
        res[0] = ((Num) result).doubleValue();
        res[1] = 0.0;
        return res;
    }
    throw new UnsupportedOperationException();
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) INumericComplex(org.matheclipse.core.eval.interfaces.INumericComplex) ISymbol(org.matheclipse.core.interfaces.ISymbol) ComplexNum(org.matheclipse.core.expression.ComplexNum) ComplexNum(org.matheclipse.core.expression.ComplexNum) Num(org.matheclipse.core.expression.Num) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

INumericComplex (org.matheclipse.core.eval.interfaces.INumericComplex)1 ComplexNum (org.matheclipse.core.expression.ComplexNum)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