/** * Returns {@code true} if this node is a type Real and represents the special IEEE * 754 value 'not a number' {@link Double#NaN}, {@code false} otherwise. * * @return {@code true} if this ASTNode is the {@link Double#NaN} */ public boolean isNaN() { return isReal() && Double.isNaN(getReal()); }
/** * Returns {@code true} if this node represents the special IEEE 754 value 'negative * infinity' {@link Double#NEGATIVE_INFINITY}, {@code false} otherwise. * * @return {@code true} if this ASTNode is {@link Double#NEGATIVE_INFINITY}, {@code false} * otherwise. */ public boolean isNegInfinity() { if (isReal()) { double real = getReal(); return Double.isInfinite(real) && (real < 0); } return false; }
/** * Returns {@code true} if this node represents the special IEEE 754 value infinity, * {@code false} otherwise. * * @return {@code true} if this ASTNode is the special IEEE 754 value infinity, * {@code false} otherwise. */ public boolean isInfinity() { if (isReal()) { double real = getReal(); return Double.isInfinite(real) && (real > 0d); } return false; }
@Override public ASTNodeValue log(ASTNode left, ASTNode right) throws SBMLException { if (left.getReal() == 10) { return function("log10", right); } else { return function("log", left, right); } }
/** * Returns {@code true} if this {@link ASTNode} represents the number one (either as * integer or as real value). * * @return {@code true} if this {@link ASTNode} represents the number one. */ public boolean isOne() { return (isReal() && getReal() == 1d) || (isInteger() && getInteger() == 1); }
@Override public ASTNodeValue root(ASTNode rootExponent, ASTNode value) throws SBMLException { if (rootExponent.isNumber() && (rootExponent.getReal() == 2d)) { return sqrt(value); } return new ASTNodeValue(concat("\\sqrt[", rootExponent, "]{", value.compile(this), Character.valueOf('}')).toString(), this); }
/** * Returns {@code true} if this node represents the number zero (either as integer * or as real value). * * @return {@code true} if this node represents the number zero. */ public boolean isZero() { return (isReal() && getReal() == 0d) || (isInteger() && getInteger() == 0); }
/** * Creates brackets if needed. * * @param node * @return * @throws SBMLException */ private String checkBrackets(ASTNode node) throws SBMLException { String term = node.compile(this).toString(); // TODO: This should be smarter if (node.isSum() || node.isDifference() || node.isUMinus()) { term = brackets(term).toString(); } else if (node.isReal()) { if (node.getReal() < 0d) { term = brackets(term).toString(); } } return term; }
/** * Returns {@code true} if this astnode represents the number minus one (either as * integer or as real value). * * @return {@code true} if this astnode represents the number minus one (either as * integer or as real value). */ public boolean isMinusOne() { return (isReal() && (getReal() == -1d)) || (isInteger() && (getInteger() == -1)) || (isUMinus() && getLeftChild().isOne()); }
/** * Creates brackets if needed. * * @param node * @return * @throws SBMLException */ protected String checkBrackets(ASTNode node) throws SBMLException { String term = node.compile(this).toString(); if (node.isSum() || node.isDifference() || node.isUMinus() || node.isRelational() || node.isLogical()) { term = brackets(term).toString(); } else if (node.isReal()) { if (node.getReal() < 0d) { term = brackets(term).toString(); } } return term; }
/** * @param value */ private void sinRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { sinRecursive(value.getChild(i)); } else if (useId){ ASTNode sinValue = new ASTNode(ASTNode.Type.FUNCTION_SIN, child.getParentSBMLObject()); sinValue.addChild(child.clone()); value.replaceChild(i, sinValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.sin(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void ceilingRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { ceilingRecursive(value.getChild(i)); } else if (useId){ ASTNode ceilValue = new ASTNode(ASTNode.Type.FUNCTION_CEILING, child.getParentSBMLObject()); ceilValue.addChild(child.clone()); value.replaceChild(i, ceilValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.ceil(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void logRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { logRecursive(value.getChild(i)); } else if (useId){ ASTNode logValue = new ASTNode(ASTNode.Type.FUNCTION_LOG, child.getParentSBMLObject()); logValue.addChild(child.clone()); value.replaceChild(i, logValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.log10(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arctanhRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arctanhRecursive(value.getChild(i)); } else if (useId){ ASTNode arctanhValue = new ASTNode(ASTNode.Type.FUNCTION_ARCTANH, child.getParentSBMLObject()); arctanhValue.addChild(child.clone()); value.replaceChild(i, arctanhValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arctanh(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void cothRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { cothRecursive(value.getChild(i)); } else if (useId){ ASTNode cothValue = new ASTNode(ASTNode.Type.FUNCTION_COTH, child.getParentSBMLObject()); cothValue.addChild(child.clone()); value.replaceChild(i, cothValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.coth(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arccothRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arccothRecursive(value.getChild(i)); } else if (useId){ ASTNode arccothValue = new ASTNode(ASTNode.Type.FUNCTION_ARCCOTH, child.getParentSBMLObject()); arccothValue.addChild(child.clone()); value.replaceChild(i, arccothValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arccoth(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arccscRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arccscRecursive(value.getChild(i)); } else if (useId){ ASTNode arccscValue = new ASTNode(ASTNode.Type.FUNCTION_ARCCSC, child.getParentSBMLObject()); arccscValue.addChild(child.clone()); value.replaceChild(i, arccscValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arccsc(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arcsecRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arcsecRecursive(value.getChild(i)); } else if (useId){ ASTNode arcsecValue = new ASTNode(ASTNode.Type.FUNCTION_ARCSEC, child.getParentSBMLObject()); arcsecValue.addChild(child.clone()); value.replaceChild(i, arcsecValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arcsec(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void coshRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isNumber()) { value.getChild(i).setValue(Math.cosh(child.getReal())); } else if (child.isVector()) { coshRecursive(value.getChild(i)); } else if (useId){ ASTNode coshValue = new ASTNode(ASTNode.Type.FUNCTION_COSH, child.getParentSBMLObject()); coshValue.addChild(child.clone()); value.replaceChild(i, coshValue); } else { throw new SBMLException(); } } }
/** * @param value */ private void cschRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { cschRecursive(value.getChild(i)); } else if (useId){ ASTNode cschValue = new ASTNode(ASTNode.Type.FUNCTION_CSCH, child.getParentSBMLObject()); cschValue.addChild(child.clone()); value.replaceChild(i, cschValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.csch(child.getReal())); } else { throw new SBMLException(); } } }