Search in sources :

Example 16 with IFraction

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

the class ComplexSym method normalize.

@Override
public INumber normalize() {
    if (fImaginary.isZero()) {
        if (fReal instanceof IFraction) {
            if (fReal.getDenominator().isOne()) {
                return fReal.getNumerator();
            }
            if (fReal.getNumerator().isZero()) {
                return F.C0;
            }
        }
        return fReal;
    }
    boolean evaled = false;
    IRational newRe = fReal;
    IRational newIm = fImaginary;
    if (fReal instanceof IFraction) {
        if (fReal.getDenominator().isOne()) {
            newRe = fReal.getNumerator();
            evaled = true;
        }
        if (fReal.getNumerator().isZero()) {
            newRe = F.C0;
            evaled = true;
        }
    }
    if (fImaginary instanceof IFraction && fImaginary.getDenominator().isOne()) {
        newIm = fImaginary.getNumerator();
        evaled = true;
    }
    return evaled ? valueOf(newRe, newIm) : this;
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IRational(org.matheclipse.core.interfaces.IRational)

Example 17 with IFraction

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

the class FractionSym method add.

@Override
public IRational add(IRational parm1) {
    if (parm1.isZero()) {
        return this;
    }
    if (parm1 instanceof IFraction) {
        return add((IFraction) parm1);
    }
    if (parm1 instanceof IntegerSym) {
        IntegerSym is = (IntegerSym) parm1;
        long newnum = fNumerator + (long) fDenominator * (long) is.fIntValue;
        return valueOf(newnum, fDenominator);
    }
    BigInteger newnum = toBigNumerator().add(toBigDenominator().multiply(parm1.toBigNumerator()));
    return valueOf(newnum, toBigDenominator());
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) BigInteger(java.math.BigInteger)

Example 18 with IFraction

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

the class BigFractionSym method add.

@Override
public IRational add(IRational parm1) {
    if (parm1.isZero()) {
        return this;
    }
    if (parm1 instanceof IFraction) {
        return add((IFraction) parm1);
    }
    IInteger p1 = (IInteger) parm1;
    BigInteger newnum = toBigNumerator().add(toBigDenominator().multiply(p1.toBigNumerator()));
    return valueOf(newnum, toBigDenominator());
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger)

Example 19 with IFraction

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

the class BigIntegerSym method add.

@Override
public IRational add(IRational parm1) {
    if (parm1.isZero()) {
        return this;
    }
    if (parm1 instanceof IFraction) {
        return ((IFraction) parm1).add(this);
    }
    IInteger p1 = (IInteger) parm1;
    BigInteger newnum = toBigNumerator().add(p1.toBigNumerator());
    return valueOf(newnum);
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger)

Example 20 with IFraction

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

the class BigIntegerSym method multiply.

@Override
public IRational multiply(IRational parm1) {
    if (parm1.isZero()) {
        return F.C0;
    }
    if (parm1.isOne()) {
        return this;
    }
    if (parm1.isMinusOne()) {
        return this.negate();
    }
    if (parm1 instanceof IFraction) {
        return ((IFraction) parm1).multiply(this);
    }
    IInteger p1 = (IInteger) parm1;
    BigInteger newnum = toBigNumerator().multiply(p1.toBigNumerator());
    return valueOf(newnum);
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger)

Aggregations

IFraction (org.matheclipse.core.interfaces.IFraction)29 IInteger (org.matheclipse.core.interfaces.IInteger)16 IExpr (org.matheclipse.core.interfaces.IExpr)14 IAST (org.matheclipse.core.interfaces.IAST)11 ISymbol (org.matheclipse.core.interfaces.ISymbol)9 BigInteger (java.math.BigInteger)8 INum (org.matheclipse.core.interfaces.INum)7 IComplex (org.matheclipse.core.interfaces.IComplex)6 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)6 GenPolynomial (edu.jas.poly.GenPolynomial)3 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)3 ExpVector (edu.jas.poly.ExpVector)2 BigFraction (org.hipparchus.fraction.BigFraction)2 JASIExpr (org.matheclipse.core.convert.JASIExpr)2 ApfloatNum (org.matheclipse.core.expression.ApfloatNum)2 IRational (org.matheclipse.core.interfaces.IRational)2 BigInteger (edu.jas.arith.BigInteger)1 BigRational (edu.jas.arith.BigRational)1 ModLong (edu.jas.arith.ModLong)1 ApcomplexNum (org.matheclipse.core.expression.ApcomplexNum)1