use of cbit.vcell.matrix.RationalNumber in project vcell by virtualcell.
the class ASTPowerTerm method toInfix.
public String toInfix(RationalNumber power) {
if (jjtGetChild(0) instanceof ASTIdNode || jjtGetChild(0) instanceof ASTIntegerBaseNode) {
if (jjtGetNumChildren() == 1) {
if (power.equals(RationalNumber.ONE)) {
return jjtGetChild(0).toInfix(power);
} else {
return jjtGetChild(0).toInfix(RationalNumber.ONE) + "^" + power.infix();
}
} else {
return jjtGetChild(0).toInfix(RationalNumber.ONE) + "^" + jjtGetChild(1).toInfix(power);
}
} else if (jjtGetNumChildren() == 1) {
return jjtGetChild(0).toInfix(power);
} else if (jjtGetNumChildren() == 2) {
if (jjtGetChild(1) instanceof ASTNegative) {
ASTNegative negNode = (ASTNegative) jjtGetChild(1);
RationalNumber exponent = negNode.getRationalNumber();
return jjtGetChild(0).toInfix(power.mult(exponent));
} else if (jjtGetChild(1) instanceof ASTRationalNumberExponent) {
ASTRationalNumberExponent rationalNumberExponent = (ASTRationalNumberExponent) jjtGetChild(1);
RationalNumber exponent = rationalNumberExponent.value;
return jjtGetChild(0).toInfix(power.mult(exponent));
} else {
throw new RuntimeException("unexpected second child " + jjtGetChild(1).getClass().getName());
}
} else {
throw new RuntimeException("unexpected unit format");
}
}
use of cbit.vcell.matrix.RationalNumber in project vcell by virtualcell.
the class ASTRationalNumberExponent method toSymbol.
public String toSymbol(RationalNumber power, UnitTextFormat format) {
RationalNumber product = value.mult(power);
double doubleValue = product.doubleValue();
int intValue = product.intValue();
switch(format) {
case plain:
{
if (intValue == doubleValue) {
return product.infix();
} else {
return "(" + product.infix() + ")";
}
}
case unicode:
{
if (intValue == doubleValue) {
if (Math.abs(intValue) < 10) {
String superScriptChar = superScripts_0_to_9[Math.abs(intValue)];
if (intValue < 0) {
return SUPER_MINUS + superScriptChar;
} else {
return superScriptChar;
}
} else {
return product.infix();
}
} else {
return "(" + product.infix() + ")";
}
}
default:
{
throw new RuntimeException("format " + format.name() + " not yet supported by UnitSymbol");
}
}
}
Aggregations