use of org.matheclipse.core.interfaces.IFraction in project symja_android_library by axkr.
the class BigFractionSym method multiply.
@Override
public IRational multiply(IRational parm1) {
if (parm1.isOne()) {
return this;
}
if (parm1.isZero()) {
return parm1;
}
if (parm1.isMinusOne()) {
return this.negate();
}
if (parm1 instanceof IFraction) {
return mul((IFraction) parm1);
}
IInteger p1 = (IInteger) parm1;
BigInteger newnum = toBigNumerator().multiply(p1.toBigNumerator());
return valueOf(newnum, toBigDenominator());
}
use of org.matheclipse.core.interfaces.IFraction in project symja_android_library by axkr.
the class AbstractArgMultiple method binaryOperator.
@Override
public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
IExpr result = F.NIL;
if (o0 instanceof INum) {
// use specialized methods for numeric mode
if (o1 instanceof INum) {
result = e2DblArg((INum) o0, (INum) o1);
} else if (o1.isInteger()) {
result = e2DblArg((INum) o0, F.num((IInteger) o1));
} else if (o1.isFraction()) {
result = e2DblArg((INum) o0, F.num((IFraction) o1));
} else if (o1 instanceof IComplexNum) {
if (o0 instanceof ApfloatNum) {
result = e2DblComArg(F.complexNum(((ApfloatNum) o0).apfloatValue()), (IComplexNum) o1);
} else {
result = e2DblComArg(F.complexNum(((INum) o0).getRealPart()), (IComplexNum) o1);
}
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof INum) {
// use specialized methods for numeric mode
if (o0.isInteger()) {
result = e2DblArg(F.num((IInteger) o0), (INum) o1);
} else if (o0.isFraction()) {
result = e2DblArg(F.num((IFraction) o0), (INum) o1);
} else if (o0 instanceof IComplexNum) {
if (o1 instanceof ApfloatNum) {
result = e2DblComArg((IComplexNum) o0, F.complexNum(((ApfloatNum) o1).apfloatValue()));
} else {
result = e2DblComArg((IComplexNum) o0, F.complexNum(((INum) o1).getRealPart()));
}
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
}
if (o0 instanceof IComplexNum) {
// use specialized methods for complex numeric mode
if (o1 instanceof INum) {
result = e2DblComArg((IComplexNum) o0, F.complexNum(((INum) o1).getRealPart()));
} else if (o1.isInteger()) {
result = e2DblComArg((IComplexNum) o0, F.complexNum((IInteger) o1));
} else if (o1.isFraction()) {
result = e2DblComArg((IComplexNum) o0, F.complexNum((IFraction) o1));
} else if (o1 instanceof IComplexNum) {
result = e2DblComArg((IComplexNum) o0, (IComplexNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof IComplexNum) {
// use specialized methods for complex numeric mode
if (o0 instanceof INum) {
result = e2DblComArg(F.complexNum(((INum) o0).getRealPart()), (IComplexNum) o1);
} else if (o0.isInteger()) {
result = e2DblComArg(F.complexNum((IInteger) o0), (IComplexNum) o1);
} else if (o0.isFraction()) {
result = e2DblComArg(F.complexNum((IFraction) o0), (IComplexNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
}
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);
}
} else 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);
}
} else if (o0 instanceof IComplex) {
if (o1 instanceof IInteger) {
return eComIntArg((IComplex) o0, (IInteger) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg((IComplex) o0, (IComplex) o1);
}
}
result = e2ObjArg(o0, o1);
if (result.isPresent()) {
return result;
}
if (o0 instanceof ISymbol) {
if (o1 instanceof ISymbol) {
return e2SymArg((ISymbol) o0, (ISymbol) o1);
}
}
if (o0 instanceof IAST) {
IAST a0 = (IAST) o0;
if (o1 instanceof IInteger) {
return eFunIntArg(a0, (IInteger) o1);
}
if (o1 instanceof IAST) {
return e2FunArg(a0, (IAST) o1);
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IFraction in project symja_android_library by axkr.
the class AbstractArg2 method binaryOperator.
public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
IExpr result = F.NIL;
if (o0.isNumber() && o1.isNumber()) {
result = e2NumericArg(o0, o1);
if (result.isPresent()) {
return result;
}
}
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.IFraction in project symja_android_library by axkr.
the class NumberTest method testPower.
public void testPower() {
IFraction f = FractionSym.valueOf(2, 3);
assertEquals(f.pow(-2).toString(), "9/4");
IFraction f0 = FractionSym.valueOf(5, 14);
assertEquals(f0.pow(2).toString(), "25/196");
}
use of org.matheclipse.core.interfaces.IFraction in project symja_android_library by axkr.
the class JASConvert method monomialToExpr.
public boolean monomialToExpr(BigRational coeff, ExpVector exp, IAST monomTimes) {
if (!coeff.isONE()) {
IFraction coeffValue = F.fraction(coeff.numerator(), coeff.denominator());
monomTimes.append(coeffValue);
}
return expVectorToExpr(exp, monomTimes);
}
Aggregations