Search in sources :

Example 16 with RationalNumber

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");
    }
}
Also used : RationalNumber(cbit.vcell.matrix.RationalNumber)

Example 17 with RationalNumber

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");
            }
    }
}
Also used : RationalNumber(cbit.vcell.matrix.RationalNumber)

Aggregations

RationalNumber (cbit.vcell.matrix.RationalNumber)17 Expression (cbit.vcell.parser.Expression)7 RationalExp (cbit.vcell.matrix.RationalExp)3 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)3 RationalMatrixFast (cbit.vcell.matrix.RationalMatrixFast)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)2 PropertyVetoException (java.beans.PropertyVetoException)2 Vector (java.util.Vector)2 SimulationContext (cbit.vcell.mapping.SimulationContext)1 SpeciesContextMapping (cbit.vcell.mapping.SpeciesContextMapping)1 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)1 StructureMapping (cbit.vcell.mapping.StructureMapping)1 Feature (cbit.vcell.model.Feature)1 Membrane (cbit.vcell.model.Membrane)1 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 ArrayList (java.util.ArrayList)1