Search in sources :

Example 21 with Apfloat

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

the class ApfloatOutput method main.

public static void main(String[] args) {
    Apfloat value = new Apfloat("6.7", 25);
    value = ApfloatMath.pow(value, -4L);
    System.out.println(value.toString());
    // Apfloat newValue = ApfloatMath.round(value, 20, RoundingMode.HALF_EVEN);
    // System.out.println(newValue.toString());
    Apfloat value2 = new Apfloat("6.7", 24);
    value2 = ApfloatMath.pow(value2, -4L);
    System.out.println(value2.toString());
    // Apfloat newValue2 = ApfloatMath.round(value2, 20, RoundingMode.HALF_EVEN);
    // System.out.println(newValue2.toString());
    Apfloat valueD = new Apfloat(Math.pow(6.7, -4));
    Apfloat newValueD = ApfloatMath.round(valueD, 6, RoundingMode.HALF_EVEN);
    System.out.println(newValueD.toString());
    Apfloat valueD2 = new Apfloat(Math.pow(6.7, -4));
    Apfloat newValueD2 = ApfloatMath.round(valueD2, 7, RoundingMode.HALF_EVEN);
    System.out.println(newValueD2.toString());
}
Also used : Apfloat(org.apfloat.Apfloat)

Example 22 with Apfloat

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

the class AbstractFractionSym method apcomplexValue.

@Override
public Apcomplex apcomplexValue() {
    FixedPrecisionApfloatHelper h = EvalEngine.getApfloat();
    Apfloat real = h.divide(new Apfloat(toBigNumerator(), h.precision()), new Apfloat(toBigDenominator(), h.precision()));
    return new Apcomplex(real);
}
Also used : FixedPrecisionApfloatHelper(org.apfloat.FixedPrecisionApfloatHelper) Apcomplex(org.apfloat.Apcomplex) Apfloat(org.apfloat.Apfloat)

Example 23 with Apfloat

use of org.apfloat.Apfloat 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 24 with Apfloat

use of org.apfloat.Apfloat 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 25 with Apfloat

use of org.apfloat.Apfloat 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

Apfloat (org.apfloat.Apfloat)29 IExpr (org.matheclipse.core.interfaces.IExpr)8 FixedPrecisionApfloatHelper (org.apfloat.FixedPrecisionApfloatHelper)7 Apcomplex (org.apfloat.Apcomplex)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 Apint (org.apfloat.Apint)3 IAST (org.matheclipse.core.interfaces.IAST)3 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)3 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 INum (org.matheclipse.core.interfaces.INum)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 BigIntegerNode (com.fasterxml.jackson.databind.node.BigIntegerNode)2 BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)2 DecimalNode (com.fasterxml.jackson.databind.node.DecimalNode)2 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)2 FloatNode (com.fasterxml.jackson.databind.node.FloatNode)2 IntNode (com.fasterxml.jackson.databind.node.IntNode)2 LongNode (com.fasterxml.jackson.databind.node.LongNode)2 NullNode (com.fasterxml.jackson.databind.node.NullNode)2