use of org.matheclipse.core.interfaces.INumber in project symja_android_library by axkr.
the class OutputFormFactory method convertPlusOperatorReversed.
private void convertPlusOperatorReversed(final Appendable buf, final IAST plusAST, final InfixOperator oper, final int precedence) throws IOException {
int operPrecedence = oper.getPrecedence();
if (operPrecedence < precedence) {
append(buf, "(");
}
String operatorStr = oper.getOperatorString();
IExpr plusArg;
int size = plusAST.size() - 1;
// print Plus[] in reverse order (i.e. numbers at last)
for (int i = size; i > 0; i--) {
plusArg = plusAST.get(i);
if (plusArg.isTimes()) {
final String multCh = ASTNodeFactory.MMA_STYLE_FACTORY.get("Times").getOperatorString();
boolean showOperator = true;
final IAST timesAST = (IAST) plusArg;
IExpr arg1 = timesAST.arg1();
if (arg1.isNumber() && (((INumber) arg1).complexSign() < 0)) {
if (((INumber) arg1).isOne()) {
showOperator = false;
} else {
if (arg1.isMinusOne()) {
append(buf, "-");
showOperator = false;
} else {
convertNumber(buf, (INumber) arg1, operPrecedence, NO_PLUS_CALL);
}
}
} else {
if (i < size) {
append(buf, operatorStr);
}
convert(buf, arg1, ASTNodeFactory.TIMES_PRECEDENCE, false);
}
IExpr timesArg;
for (int j = 2; j < timesAST.size(); j++) {
timesArg = timesAST.get(j);
if (showOperator) {
append(buf, multCh);
} else {
showOperator = true;
}
convert(buf, timesArg, ASTNodeFactory.TIMES_PRECEDENCE, false);
}
} else {
if (plusArg.isNumber() && (((INumber) plusArg).complexSign() < 0)) {
// special case negative number:
convert(buf, plusArg);
} else {
if (i < size) {
append(buf, operatorStr);
}
convert(buf, plusArg, ASTNodeFactory.PLUS_PRECEDENCE, false);
}
}
}
if (operPrecedence < precedence) {
append(buf, ")");
}
}
use of org.matheclipse.core.interfaces.INumber 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.interfaces.INumber in project symja_android_library by axkr.
the class TableGenerator method tableTimes.
private IExpr tableTimes(IExpr temp, final IIterator<IExpr> iter, final int index) {
INumber num;
int counter = 0;
num = (INumber) temp;
while (iter.hasNext()) {
fCurrentIndex[index] = iter.next();
temp = table();
if (temp == null) {
temp = fDefaultValue;
}
if (temp.isNumber()) {
num = (INumber) num.times((INumber) temp);
} else {
return createGenericTable(iter, index, iter.allocHint() - counter, num, temp);
}
counter++;
}
return num;
}
use of org.matheclipse.core.interfaces.INumber in project symja_android_library by axkr.
the class TableGenerator method tablePlus.
private IExpr tablePlus(IExpr temp, final IIterator<IExpr> iter, final int index) {
INumber num;
int counter = 0;
num = (INumber) temp;
while (iter.hasNext()) {
fCurrentIndex[index] = iter.next();
temp = table();
if (temp == null) {
temp = fDefaultValue;
}
if (temp.isNumber()) {
num = (INumber) num.plus((INumber) temp);
} else {
return createGenericTable(iter, index, iter.allocHint() - counter, num, temp);
}
counter++;
}
return num;
}
use of org.matheclipse.core.interfaces.INumber in project symja_android_library by axkr.
the class Sign method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 2);
IExpr arg1 = ast.arg1();
if (arg1.isNumber()) {
return numberSign((INumber) arg1);
}
if (arg1.isIndeterminate()) {
return F.Indeterminate;
}
if (arg1.isDirectedInfinity()) {
IAST directedInfininty = (IAST) arg1;
if (directedInfininty.isComplexInfinity()) {
return F.Indeterminate;
}
if (directedInfininty.isAST1()) {
return F.Sign(directedInfininty.arg1());
}
}
if (arg1.isTimes()) {
IAST[] result = ((IAST) arg1).filter(new SignTimesFunction());
if (result[0].size() > 1) {
if (result[1].size() > 1) {
result[0].append(F.Sign(result[1]));
}
return result[0];
}
}
if (arg1.isPower() && arg1.getAt(2).isSignedNumber()) {
return F.Power(F.Sign(arg1.getAt(1)), arg1.getAt(2));
}
if (AbstractAssumptions.assumeNegative(arg1)) {
return F.CN1;
}
if (AbstractAssumptions.assumePositive(arg1)) {
return F.C1;
}
IExpr negExpr = AbstractFunctionEvaluator.getNormalizedNegativeExpression(arg1);
if (negExpr.isPresent()) {
return F.Times(F.CN1, F.Sign(negExpr));
}
INumber number = arg1.evalNumber();
if (number != null) {
return numberSign(number);
}
return F.NIL;
}
Aggregations