Search in sources :

Example 1 with ApfloatNum

use of org.matheclipse.core.expression.ApfloatNum in project symja_android_library by axkr.

the class AbstractArg1 method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    final IExpr arg1 = ast.arg1();
    final IExpr result = e1ObjArg(arg1);
    if (result.isPresent()) {
        return result;
    }
    // argument dispatching
    if (arg1 instanceof IAST) {
        return e1FunArg((IAST) arg1);
    }
    final int hier = ast.arg1().hierarchy();
    if (hier <= IExpr.INTEGERID) {
        if (hier <= IExpr.DOUBLECOMPLEXID) {
            if (hier == IExpr.DOUBLEID) {
                if (arg1 instanceof ApfloatNum) {
                    return e1ApfloatArg(((ApfloatNum) arg1).apfloatValue());
                }
                return e1DblArg(((Num) arg1).doubleValue());
            }
            if (arg1 instanceof ApcomplexNum) {
                return e1ApcomplexArg(((ApcomplexNum) arg1).apcomplexValue());
            }
            return e1ComplexArg(((ComplexNum) arg1).complexValue());
        } else {
            return e1IntArg((IInteger) arg1);
        }
    } else {
        if (hier <= IExpr.COMPLEXID) {
            if (hier == IExpr.FRACTIONID) {
                return e1FraArg((IFraction) ast.arg1());
            }
            return e1ComArg((IComplex) ast.arg1());
        } else {
            if (hier == IExpr.SYMBOLID) {
                return e1SymArg((ISymbol) ast.arg1());
            }
        }
    }
    return F.NIL;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) ApcomplexNum(org.matheclipse.core.expression.ApcomplexNum)

Example 2 with ApfloatNum

use of org.matheclipse.core.expression.ApfloatNum 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;
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IComplex(org.matheclipse.core.interfaces.IComplex) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) ISymbol(org.matheclipse.core.interfaces.ISymbol) INumber(org.matheclipse.core.interfaces.INumber) IInteger(org.matheclipse.core.interfaces.IInteger) ComplexNum(org.matheclipse.core.expression.ComplexNum) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) INum(org.matheclipse.core.interfaces.INum) ApcomplexNum(org.matheclipse.core.expression.ApcomplexNum) ComplexNum(org.matheclipse.core.expression.ComplexNum) Num(org.matheclipse.core.expression.Num) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) ApcomplexNum(org.matheclipse.core.expression.ApcomplexNum)

Example 3 with ApfloatNum

use of org.matheclipse.core.expression.ApfloatNum 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;
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IComplex(org.matheclipse.core.interfaces.IComplex) ISymbol(org.matheclipse.core.interfaces.ISymbol) IInteger(org.matheclipse.core.interfaces.IInteger) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) INum(org.matheclipse.core.interfaces.INum)

Example 4 with ApfloatNum

use of org.matheclipse.core.expression.ApfloatNum in project symja_android_library by axkr.

the class AbstractArg12 method unaryOperator.

public IExpr unaryOperator(final IExpr arg0) {
    final IExpr result = e1ObjArg(arg0);
    if (result.isPresent()) {
        return result;
    }
    // argument dispatching
    if (arg0 instanceof IAST) {
        e1FunArg((IAST) arg0);
    }
    final int hier = arg0.hierarchy();
    if (hier <= IExpr.INTEGERID) {
        if (hier <= IExpr.DOUBLECOMPLEXID) {
            if (hier == IExpr.DOUBLEID) {
                if (arg0 instanceof ApfloatNum) {
                    return e1ApfloatArg(((ApfloatNum) arg0).apfloatValue());
                }
                return e1DblArg((INum) arg0);
            }
            if (arg0 instanceof ApcomplexNum) {
                return e1ApcomplexArg(((ApcomplexNum) arg0).apcomplexValue());
            }
            return e1DblComArg((IComplexNum) arg0);
        } else {
            return e1IntArg((IInteger) arg0);
        }
    } else {
        if (hier <= IExpr.COMPLEXID) {
            if (hier == IExpr.FRACTIONID) {
                return e1FraArg((IFraction) arg0);
            }
            return e1ComArg((IComplex) arg0);
        } else {
            if (hier == IExpr.SYMBOLID) {
                return e1SymArg((ISymbol) arg0);
            }
        }
    }
    return F.NIL;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) ApcomplexNum(org.matheclipse.core.expression.ApcomplexNum)

Example 5 with ApfloatNum

use of org.matheclipse.core.expression.ApfloatNum in project symja_android_library by axkr.

the class AbstractTrigArg1 method numericEval.

@Override
public IExpr numericEval(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    IExpr arg1 = ast.arg1();
    if (arg1 instanceof INum) {
        if (arg1 instanceof ApfloatNum) {
            return e1ApfloatArg(((ApfloatNum) arg1).apfloatValue());
        }
        return e1DblArg(((Num) arg1).doubleValue());
    }
    if (arg1 instanceof IComplexNum) {
        if (arg1 instanceof ApcomplexNum) {
            return e1ApcomplexArg(((ApcomplexNum) arg1).apcomplexValue());
        }
        return e1ComplexArg(((ComplexNum) arg1).complexValue());
    }
    return evaluateArg1(arg1);
}
Also used : IComplexNum(org.matheclipse.core.interfaces.IComplexNum) IExpr(org.matheclipse.core.interfaces.IExpr) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) ApcomplexNum(org.matheclipse.core.expression.ApcomplexNum) INum(org.matheclipse.core.interfaces.INum)

Aggregations

ApfloatNum (org.matheclipse.core.expression.ApfloatNum)5 IExpr (org.matheclipse.core.interfaces.IExpr)5 ApcomplexNum (org.matheclipse.core.expression.ApcomplexNum)4 IAST (org.matheclipse.core.interfaces.IAST)4 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)3 INum (org.matheclipse.core.interfaces.INum)3 IComplex (org.matheclipse.core.interfaces.IComplex)2 IFraction (org.matheclipse.core.interfaces.IFraction)2 IInteger (org.matheclipse.core.interfaces.IInteger)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2 ComplexNum (org.matheclipse.core.expression.ComplexNum)1 Num (org.matheclipse.core.expression.Num)1 INumber (org.matheclipse.core.interfaces.INumber)1 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)1