use of org.apfloat.Apfloat in project symja_android_library by axkr.
the class TeXFormFactory method convertApcomplex.
public void convertApcomplex(final StringBuilder buf, final Apcomplex dc, final int precedence, boolean caller) {
if (Precedence.PLUS < precedence) {
if (caller == PLUS_CALL) {
buf.append(" + ");
caller = false;
}
buf.append("\\left( ");
}
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) {
buf.append(convertApfloatToFormattedString(realPart));
if (!imaginaryZero) {
buf.append(" + ");
final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
convertDoubleString(buf, convertApfloatToFormattedString(imaginaryPart), Precedence.TIMES, isNegative);
// InvisibleTimes
buf.append("\\,");
buf.append("i ");
}
} else {
if (caller == PLUS_CALL) {
buf.append("+");
caller = false;
}
final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
convertDoubleString(buf, convertApfloatToFormattedString(imaginaryPart), Precedence.TIMES, isNegative);
// InvisibleTimes
buf.append("\\,");
buf.append("i ");
}
}
if (Precedence.PLUS < precedence) {
buf.append("\\right) ");
}
}
use of org.apfloat.Apfloat in project symja_android_library by axkr.
the class MathMLFormFactory method convertApcomplex.
public void convertApcomplex(final StringBuilder buf, final Apcomplex ac, final int precedence) {
Apfloat realPart = ac.real();
Apfloat imaginaryPart = ac.imag();
final boolean isImNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
tagStart(buf, "mrow");
if (Precedence.PLUS < precedence) {
tag(buf, "mo", "(");
}
// convertApfloat(buf, realPart);
buf.append(convertApfloatToFormattedString(realPart));
if (isImNegative) {
tag(buf, "mo", "-");
imaginaryPart = imaginaryPart.negate();
} else {
tag(buf, "mo", "+");
}
// convertApfloat(buf, imaginaryPart);
buf.append(convertApfloatToFormattedString(imaginaryPart));
// <!ENTITY InvisibleTimes "⁢" >
// <!ENTITY CenterDot "·" >
tag(buf, "mo", "·");
// <!ENTITY ImaginaryI "ⅈ" >
// "ⅈ");
tag(buf, "mi", "ⅈ");
if (Precedence.PLUS < precedence) {
tag(buf, "mo", ")");
}
tagEnd(buf, "mrow");
}
use of org.apfloat.Apfloat in project symja_android_library by axkr.
the class DoubleFormFactory 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 FuzzyParser method getNumber.
/**
* Method Declaration.
*
* @return
* @see
*/
private IExpr getNumber(final boolean negative) throws SyntaxError {
IExpr temp = null;
final Object[] result = getNumberString();
String number = (String) result[0];
int numFormat = ((Integer) result[1]);
try {
if (negative) {
number = '-' + number;
}
if (numFormat == 10 && fCurrentChar == '`') {
numFormat = -1;
}
if (numFormat < 0) {
if (fCurrentChar == '`' && isValidPosition()) {
fCurrentPosition++;
if (isValidPosition() && fInputString[fCurrentPosition] == '`') {
fCurrentPosition += 2;
long precision = getJavaLong();
if (precision < ParserConfig.MACHINE_PRECISION) {
precision = ParserConfig.MACHINE_PRECISION;
}
return F.num(new Apfloat(number, precision));
} else {
fCurrentPosition++;
long precision = getJavaLong();
if (precision < ParserConfig.MACHINE_PRECISION) {
precision = ParserConfig.MACHINE_PRECISION;
}
return F.num(new Apfloat(number, precision));
}
}
temp = new NumStr(number);
// temp = fFactory.createDouble(number);
} else {
temp = F.ZZ(number, numFormat);
// temp = fFactory.createInteger(number, numFormat);
}
} catch (final RuntimeException rex) {
throwSyntaxError("Number format error: " + number, number.length());
}
getNextToken();
return temp;
}
Aggregations