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, ")");
}
}
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());
}
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, ")");
}
}
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);
}
}
}
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);
}
Aggregations