Search in sources :

Example 11 with Apfloat

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

the class OutputFormFactory method convertApcomplex.

public void convertApcomplex(final Appendable buf, final Apcomplex dc, final int precedence, boolean caller) throws IOException {
    if (Precedence.PLUS < precedence) {
        if (caller == PLUS_CALL) {
            append(buf, fInputForm ? " + " : "+");
            caller = false;
        }
        append(buf, "(");
    }
    Apfloat realPart = dc.real();
    Apfloat imaginaryPart = dc.imag();
    boolean realZero = realPart.equals(Apcomplex.ZERO);
    boolean imaginaryZero = imaginaryPart.equals(Apcomplex.ZERO);
    if (realZero && imaginaryZero) {
        convertDoubleString(buf, "0.0", Precedence.PLUS, false);
    } else {
        if (!realZero) {
            String str = fInputForm ? ApfloatNum.fullFormString(realPart) : convertApfloatToFormattedString(realPart);
            append(buf, str);
            if (!imaginaryZero) {
                append(buf, "+I*");
                final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
                str = fInputForm ? ApfloatNum.fullFormString(imaginaryPart) : convertApfloatToFormattedString(imaginaryPart);
                convertDoubleString(buf, str, Precedence.TIMES, isNegative);
            }
        } else {
            if (caller == PLUS_CALL) {
                append(buf, fInputForm ? " + " : "+");
                caller = false;
            }
            append(buf, "I*");
            final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
            String str = fInputForm ? ApfloatNum.fullFormString(imaginaryPart) : convertApfloatToFormattedString(imaginaryPart);
            convertDoubleString(buf, str, Precedence.TIMES, isNegative);
        }
    }
    if (Precedence.PLUS < precedence) {
        append(buf, ")");
    }
}
Also used : Apfloat(org.apfloat.Apfloat)

Example 12 with Apfloat

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

the class ApfloatToMMATest method test0018.

public void test0018() {
    StringBuilder buf = new StringBuilder();
    ApfloatToMMA.apfloatToMMA(buf, new Apfloat(Math.pow(6.7, 8)), 3, 5, true);
    assertEquals("4.06067*10^6", buf.toString());
}
Also used : Apfloat(org.apfloat.Apfloat)

Example 13 with Apfloat

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

the class ComplexFormFactory method convertApcomplex.

public void convertApcomplex(final StringBuilder buf, final Apcomplex dc, final int precedence, boolean caller) {
    if (Precedence.PLUS < precedence) {
        if (caller == PLUS_CALL) {
            append(buf, "+");
            caller = false;
        }
        append(buf, "(");
    }
    Apfloat realPart = dc.real();
    Apfloat imaginaryPart = dc.imag();
    boolean realZero = realPart.equals(Apcomplex.ZERO);
    boolean imaginaryZero = imaginaryPart.equals(Apcomplex.ZERO);
    if (realZero && imaginaryZero) {
        convertDoubleString(buf, "0.0", Precedence.PLUS, false);
    } else {
        if (!realZero) {
            append(buf, convertApfloat(realPart));
            if (!imaginaryZero) {
                append(buf, "+I*");
                final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
                convertDoubleString(buf, convertApfloat(imaginaryPart), Precedence.TIMES, isNegative);
            }
        } else {
            if (caller == PLUS_CALL) {
                append(buf, "+");
                caller = false;
            }
            append(buf, "I*");
            final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
            convertDoubleString(buf, convertApfloat(imaginaryPart), Precedence.TIMES, isNegative);
        }
    }
    if (Precedence.PLUS < precedence) {
        append(buf, ")");
    }
}
Also used : Apfloat(org.apfloat.Apfloat)

Example 14 with Apfloat

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

the class OutputFormFactory method convertDouble.

private void convertDouble(final Appendable buf, final double doubleValue, final INum d, final int precedence, boolean caller) throws IOException {
    final boolean isNegative = d.isNegative();
    if (d instanceof ApfloatNum) {
        Apfloat apfloat = ((ApfloatNum) d).apfloatValue();
        if (!isNegative && caller == PLUS_CALL) {
            append(buf, fInputForm ? " + " : "+");
        }
        String str = fInputForm ? ApfloatNum.fullFormString(apfloat) : convertApfloatToFormattedString(apfloat);
        convertDoubleString(buf, str, precedence, isNegative);
        return;
    }
    if (F.isZero(doubleValue, Config.ZERO_IN_OUTPUT_FORMAT)) {
        if (fInputForm) {
            convertDoubleString(buf, d.fullFormString(), precedence, false);
        } else {
            convertDoubleString(buf, convertDoubleToFormattedString(0.0), precedence, false);
        }
        return;
    }
    if (!isNegative && caller == PLUS_CALL) {
        append(buf, fInputForm ? " + " : "+");
    }
    if (d instanceof Num) {
        if (fInputForm) {
            convertDoubleString(buf, d.fullFormString(), precedence, isNegative);
        } else {
            convertDoubleString(buf, convertDoubleToFormattedString(doubleValue), precedence, isNegative);
        }
    }
}
Also used : Num(org.matheclipse.core.expression.Num) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) INum(org.matheclipse.core.interfaces.INum) ApcomplexNum(org.matheclipse.core.expression.ApcomplexNum) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) Apfloat(org.apfloat.Apfloat)

Example 15 with Apfloat

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

the class ApcomplexNum method valueOf.

/**
	 * Create a <code>ApcomplexNum</code> complex number from the real and imaginary <code>BigInteger</code> parts.
	 * 
	 * @param realNumerator
	 *            the real numbers numerator part
	 * @param realDenominator
	 *            the real numbers denominator part
	 * @param imagNumerator
	 *            the imaginary numbers numerator part
	 * @param imagDenominator
	 *            the imaginary numbers denominator part
	 * @param precision
	 *            the precision of the number.
	 * @return a new <code>ApcomplexNum</code> complex number object
	 */
public static ApcomplexNum valueOf(final BigInteger realNumerator, final BigInteger realDenominator, final BigInteger imagNumerator, final BigInteger imagDenominator, int precision) {
    Apfloat real = new Apfloat(realNumerator, precision).divide(new Apfloat(realDenominator, precision));
    Apfloat imag = new Apfloat(imagNumerator, precision).divide(new Apfloat(imagDenominator, precision));
    return new ApcomplexNum(real, imag);
}
Also used : 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