Search in sources :

Example 6 with FixedPrecisionApfloatHelper

use of org.apfloat.FixedPrecisionApfloatHelper in project symja_android_library by axkr.

the class ApfloatNum method valueOf.

public static ApfloatNum valueOf(final BigInteger numerator, final BigInteger denominator) {
    FixedPrecisionApfloatHelper h = EvalEngine.getApfloat();
    Apfloat n = new Apfloat(numerator, h.precision());
    Apfloat d = new Apfloat(denominator, h.precision());
    return new ApfloatNum(h.divide(n, d));
}
Also used : FixedPrecisionApfloatHelper(org.apfloat.FixedPrecisionApfloatHelper) Apfloat(org.apfloat.Apfloat)

Example 7 with FixedPrecisionApfloatHelper

use of org.apfloat.FixedPrecisionApfloatHelper in project symja_android_library by axkr.

the class ApcomplexNum method atan2.

@Override
public IExpr atan2(IExpr value) {
    try {
        if (value instanceof ApcomplexNum) {
            Apcomplex th = fApcomplex;
            Apcomplex x = ((ApcomplexNum) value).fApcomplex;
            // compute r = sqrt(x^2+y^2)
            FixedPrecisionApfloatHelper h = EvalEngine.getApfloat();
            final Apcomplex r = h.sqrt(h.add(h.multiply(x, x), h.multiply(th, th)));
            if (x.real().compareTo(Apfloat.ZERO) >= 0) {
                // compute atan2(y, x) = 2 atan(y / (r + x))
                return valueOf(h.multiply(h.atan(h.divide(th, h.add(r, x))), new Apfloat(2)));
            } else {
                // compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
                return valueOf(h.add(h.multiply(h.atan(h.divide(th, h.subtract(r, x))), new Apfloat(-2)), h.pi()));
            }
        }
        return IComplexNum.super.atan2(value);
    } catch (ArithmeticException aex) {
        // Indeterminate expression `1` encountered.
        IOFunctions.printMessage(S.ArcTan, "indet", F.list(F.ArcTan(value, this)), EvalEngine.get());
        return S.Indeterminate;
    }
}
Also used : FixedPrecisionApfloatHelper(org.apfloat.FixedPrecisionApfloatHelper) Apcomplex(org.apfloat.Apcomplex) Apfloat(org.apfloat.Apfloat)

Example 8 with FixedPrecisionApfloatHelper

use of org.apfloat.FixedPrecisionApfloatHelper in project symja_android_library by axkr.

the class ApcomplexNum method copySign.

@Override
public IExpr copySign(double d) {
    FixedPrecisionApfloatHelper h = EvalEngine.getApfloat();
    Apfloat sign = new Apfloat(d);
    return valueOf(// 
    h.copySign(fApcomplex.real(), sign), h.copySign(fApcomplex.imag(), sign));
}
Also used : FixedPrecisionApfloatHelper(org.apfloat.FixedPrecisionApfloatHelper) Apfloat(org.apfloat.Apfloat)

Aggregations

FixedPrecisionApfloatHelper (org.apfloat.FixedPrecisionApfloatHelper)8 Apfloat (org.apfloat.Apfloat)7 Apcomplex (org.apfloat.Apcomplex)3 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 INum (org.matheclipse.core.interfaces.INum)1