use of org.matheclipse.core.expression.ComplexNum in project symja_android_library by axkr.
the class AbstractArg12 method binaryOperator.
public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
IExpr result = F.NIL;
if (o0 instanceof ApcomplexNum) {
if (o1.isNumber()) {
result = e2ApcomplexArg((ApcomplexNum) o0, ((INumber) o1).apcomplexNumValue(((ApcomplexNum) o0).precision()));
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ApcomplexNum) {
if (o0.isNumber()) {
result = e2ApcomplexArg(((INumber) o0).apcomplexNumValue(((ApcomplexNum) o1).precision()), (ApcomplexNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o0 instanceof ComplexNum) {
if (o1.isNumber()) {
result = e2DblComArg((ComplexNum) o0, ((INumber) o1).complexNumValue());
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ComplexNum) {
if (o0.isNumber()) {
result = e2DblComArg(((INumber) o0).complexNumValue(), (ComplexNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
}
if (o0 instanceof ApfloatNum) {
if (o1.isSignedNumber()) {
result = e2ApfloatArg((ApfloatNum) o0, ((ISignedNumber) o1).apfloatNumValue(((ApfloatNum) o0).precision()));
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ApfloatNum) {
if (o0.isSignedNumber()) {
result = e2ApfloatArg(((ISignedNumber) o0).apfloatNumValue(((ApfloatNum) o1).precision()), (ApfloatNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o0 instanceof Num) {
if (o1.isSignedNumber()) {
result = e2DblArg((Num) o0, ((ISignedNumber) o1).numValue());
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof Num) {
if (o0.isSignedNumber()) {
result = e2DblArg(((ISignedNumber) o0).numValue(), (Num) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
}
result = e2ObjArg(o0, o1);
if (result.isPresent()) {
return result;
}
if (o0 instanceof IInteger) {
if (o1 instanceof IInteger) {
return e2IntArg((IInteger) o0, (IInteger) o1);
}
if (o1 instanceof IFraction) {
return e2FraArg(F.fraction((IInteger) o0, F.C1), (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg(F.complex((IInteger) o0, F.C0), (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof IFraction) {
if (o1 instanceof IInteger) {
return e2FraArg((IFraction) o0, F.fraction((IInteger) o1, F.C1));
}
if (o1 instanceof IFraction) {
return e2FraArg((IFraction) o0, (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg(F.complex((IFraction) o0), (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof IComplex) {
if (o1 instanceof IInteger) {
return eComIntArg((IComplex) o0, (IInteger) o1);
}
if (o1 instanceof IFraction) {
return eComFraArg((IComplex) o0, (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg((IComplex) o0, (IComplex) o1);
}
}
if (o0 instanceof ISymbol) {
if (o1 instanceof ISymbol) {
return e2SymArg((ISymbol) o0, (ISymbol) o1);
}
}
if (o0 instanceof IAST) {
if (o1 instanceof IInteger) {
return eFunIntArg((IAST) o0, (IInteger) o1);
}
if (o1 instanceof IAST) {
return e2FunArg((IAST) o0, (IAST) o1);
}
}
return F.NIL;
}
use of org.matheclipse.core.expression.ComplexNum in project symja_android_library by axkr.
the class AbstractArg12 method binaryOperator.
public IExpr binaryOperator(IAST ast, final IExpr o0, final IExpr o1) {
IExpr result = e2ObjArg(o0, o1);
if (result.isPresent()) {
return result;
}
if (o0.isInexactNumber() && o1.isInexactNumber()) {
try {
EvalEngine engine = EvalEngine.get();
INumber arg1 = ((INumber) o0).evaluatePrecision(engine);
INumber arg2 = ((INumber) o1).evaluatePrecision(engine);
if (arg1 instanceof ApcomplexNum) {
if (arg2.isNumber()) {
result = e2ApcomplexArg((ApcomplexNum) arg1, arg2.apcomplexNumValue());
}
} else if (arg2 instanceof ApcomplexNum) {
if (arg1.isNumber()) {
result = e2ApcomplexArg(arg1.apcomplexNumValue(), (ApcomplexNum) arg2);
}
} else if (arg1 instanceof ComplexNum) {
if (arg2.isNumber()) {
result = e2DblComArg((ComplexNum) arg1, arg2.complexNumValue());
}
} else if (arg2 instanceof ComplexNum) {
if (arg1.isNumber()) {
result = e2DblComArg(arg1.complexNumValue(), (ComplexNum) arg2);
}
}
if (arg1 instanceof ApfloatNum) {
if (arg2.isReal()) {
result = e2ApfloatArg((ApfloatNum) arg1, ((ISignedNumber) arg2).apfloatNumValue());
}
} else if (arg2 instanceof ApfloatNum) {
if (arg1.isReal()) {
result = e2ApfloatArg(((ISignedNumber) arg1).apfloatNumValue(), (ApfloatNum) arg2);
}
} else if (arg1 instanceof Num) {
if (arg2.isReal()) {
result = e2DblArg((Num) arg1, ((ISignedNumber) arg2).numValue());
}
} else if (arg2 instanceof Num) {
if (arg1.isReal()) {
result = e2DblArg(((ISignedNumber) arg1).numValue(), (Num) arg2);
}
}
if (result.isPresent()) {
return result;
}
} catch (LimitException le) {
throw le;
} catch (RuntimeException rex) {
LOGGER.debug("AbstractArg12.binaryOperator() failed", rex);
return F.NIL;
}
}
if (o0 instanceof IInteger) {
if (o1 instanceof IInteger) {
return e2IntArg((IInteger) o0, (IInteger) o1);
}
if (o1 instanceof IFraction) {
return e2FraArg(F.fraction((IInteger) o0, F.C1), (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg(F.complex((IInteger) o0, F.C0), (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof IFraction) {
if (o1 instanceof IInteger) {
return e2FraArg((IFraction) o0, F.fraction((IInteger) o1, F.C1));
}
if (o1 instanceof IFraction) {
return e2FraArg((IFraction) o0, (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg(F.complex((IFraction) o0), (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof IComplex) {
if (o1 instanceof IInteger) {
return eComIntArg((IComplex) o0, (IInteger) o1);
}
if (o1 instanceof IFraction) {
return eComFraArg((IComplex) o0, (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg((IComplex) o0, (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof ISymbol) {
if (o1 instanceof ISymbol) {
return e2SymArg((ISymbol) o0, (ISymbol) o1);
}
return F.NIL;
}
if (o0 instanceof IAST) {
if (o1 instanceof IInteger) {
return eFunIntArg((IAST) o0, (IInteger) o1);
}
if (o1 instanceof IAST) {
return e2FunArg((IAST) o0, (IAST) o1);
}
}
return F.NIL;
}
use of org.matheclipse.core.expression.ComplexNum 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.argSize());
}
}
// 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();
}
use of org.matheclipse.core.expression.ComplexNum in project symja_android_library by axkr.
the class EvalComplex method evalSymbol.
public static double[] evalSymbol(final ISymbol symbol) {
IExpr expr = symbol.assignedValue();
if (expr != null) {
// 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.isRealConstant()) {
// 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();
}
use of org.matheclipse.core.expression.ComplexNum in project symja_android_library by axkr.
the class NumberTest method testComplexNum.
public void testComplexNum() {
// test for Android bug:
// https://github.com/tranleduy2000/symja_android_library/commit/2f03d0b6c8095c2c71b1f56c8e5fc5f0b30f927d
// 3802951800684688204490109616127/1267650600228229401496703205376
IFraction f = AbstractFractionSym.valueOf(new BigInteger("3802951800684688204490109616127"), new BigInteger("1267650600228229401496703205376"));
ComplexNum cn = f.complexNumValue();
assertEquals(cn.toString(), "(3.0)");
// 2535301200456458802993406410751/1267650600228229401496703205376
f = AbstractFractionSym.valueOf(new BigInteger("2535301200456458802993406410751"), new BigInteger("1267650600228229401496703205376"));
cn = f.complexNumValue();
assertEquals(cn.toString(), "(2.0)");
}
Aggregations