Search in sources :

Example 1 with INumericComplexConstant

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

the class EvalComplex method evalSymbol.

public static double[] evalSymbol(final ISymbol symbol) {
    if (symbol.hasLocalVariableStack()) {
        final IExpr expr = symbol.get();
        if (expr instanceof ISignedNumber) {
            final double[] result = new double[2];
            result[0] = ((ISignedNumber) expr).doubleValue();
            result[1] = 0.0;
            return result;
        }
        if (expr instanceof ComplexNum) {
            final double[] result = new double[2];
            result[0] = ((ComplexNum) expr).getRealPart();
            result[1] = ((ComplexNum) expr).getImaginaryPart();
            return result;
        }
    }
    if (symbol.isSignedNumberConstant()) {
        // fast evaluation path
        final double[] result = new double[2];
        result[0] = ((ISignedNumberConstant) ((IBuiltInSymbol) symbol).getEvaluator()).evalReal();
        result[1] = 0.0;
        return result;
    }
    if (symbol.isBuiltInSymbol()) {
        final IEvaluator module = ((IBuiltInSymbol) symbol).getEvaluator();
        if (module instanceof INumericComplexConstant) {
            // fast evaluation path
            return ((INumericComplexConstant) module).evalComplex();
        }
    }
    // slow evaluation path
    final IExpr result = F.evaln(symbol);
    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) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) ComplexNum(org.matheclipse.core.expression.ComplexNum) ComplexNum(org.matheclipse.core.expression.ComplexNum) Num(org.matheclipse.core.expression.Num) IExpr(org.matheclipse.core.interfaces.IExpr) INumericComplexConstant(org.matheclipse.core.eval.interfaces.INumericComplexConstant)

Aggregations

INumericComplexConstant (org.matheclipse.core.eval.interfaces.INumericComplexConstant)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 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)1