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();
}
Aggregations