static private float asFloat(Node n) { if ( n == null ) return Float.MIN_VALUE ; NodeValue nv = NodeValue.makeNode(n) ; if ( nv.isFloat() ) return nv.getFloat() ; return Float.MIN_VALUE ; }
private static int intValueStr(NodeValue nv, int valueNan) { if ( nv.isInteger() ) return nv.getInteger().intValue() ; if ( nv.isDecimal() ) // No decimal round in Java 1.4 return (int)Math.round(nv.getDecimal().doubleValue()) ; if ( nv.isFloat() ) { float f = nv.getFloat() ; if ( Float.isNaN(f)) return valueNan ; return Math.round(f) ; } if ( nv.isDouble() ) { double d = nv.getDouble() ; if ( Double.isNaN(d)) return valueNan ; return (int)Math.round(d) ; } throw new ExprEvalException("Not a number:"+nv) ; }
private static int intValueStr(NodeValue nv, int valueNan) { if ( nv.isInteger() ) return nv.getInteger().intValue() ; if ( nv.isDecimal() ) // No decimal round in Java 1.4 return (int)Math.round(nv.getDecimal().doubleValue()) ; if ( nv.isFloat() ) { float f = nv.getFloat() ; if ( Float.isNaN(f)) return valueNan ; return Math.round(f) ; } if ( nv.isDouble() ) { double d = nv.getDouble() ; if ( Double.isNaN(d)) return valueNan ; return (int)Math.round(d) ; } throw new ExprEvalException("Not a number:"+nv) ; }
public static NodeValue floor(NodeValue v) { switch (classifyNumeric("floor", v)) { case OP_INTEGER: return v ; case OP_DECIMAL: BigDecimal dec = v.getDecimal().setScale(0, BigDecimal.ROUND_FLOOR) ; return NodeValue.makeDecimal(dec) ; case OP_FLOAT: return NodeValue.makeFloat( (float)Math.floor(v.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.floor(v.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
public static NodeValue floor(NodeValue v) { switch (classifyNumeric("floor", v)) { case OP_INTEGER: return v ; case OP_DECIMAL: BigDecimal dec = v.getDecimal().setScale(0, BigDecimal.ROUND_FLOOR) ; return NodeValue.makeDecimal(dec) ; case OP_FLOAT: return NodeValue.makeFloat( (float)Math.floor(v.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.floor(v.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
public static int compareNumeric(NodeValue nv1, NodeValue nv2) { NumericType opType = classifyNumeric("compareNumeric", nv1, nv2) ; switch (opType) { case OP_INTEGER: return calcReturn(nv1.getInteger().compareTo(nv2.getInteger())) ; case OP_DECIMAL: return calcReturn(nv1.getDecimal().compareTo(nv2.getDecimal())) ; case OP_FLOAT: return calcReturn(Float.compare(nv1.getFloat(), nv2.getFloat())) ; case OP_DOUBLE: return calcReturn(Double.compare(nv1.getDouble(), nv2.getDouble())) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue ceiling(NodeValue v) { switch (classifyNumeric("ceiling", v)) { case OP_INTEGER: return v ; case OP_DECIMAL: BigDecimal dec = v.getDecimal().setScale( 0, BigDecimal.ROUND_CEILING) ; return NodeValue.makeDecimal(dec) ; case OP_FLOAT: return NodeValue.makeFloat( (float)Math.ceil(v.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.ceil(v.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
public static int compareNumeric(NodeValue nv1, NodeValue nv2) { NumericType opType = classifyNumeric("compareNumeric", nv1, nv2) ; switch (opType) { case OP_INTEGER: return calcReturn(nv1.getInteger().compareTo(nv2.getInteger())) ; case OP_DECIMAL: return calcReturn(nv1.getDecimal().compareTo(nv2.getDecimal())) ; case OP_FLOAT: return calcReturn(Float.compare(nv1.getFloat(), nv2.getFloat())) ; case OP_DOUBLE: return calcReturn(Double.compare(nv1.getDouble(), nv2.getDouble())) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue abs(NodeValue nv) { switch (classifyNumeric("abs", nv)) { case OP_INTEGER: return NodeValue.makeInteger(nv.getInteger().abs()) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv.getDecimal().abs()) ; case OP_FLOAT: return NodeValue.makeFloat( Math.abs(nv.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.abs(nv.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+nv) ; } }
public static NodeValue abs(NodeValue nv) { switch (classifyNumeric("abs", nv)) { case OP_INTEGER: return NodeValue.makeInteger(nv.getInteger().abs()) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv.getDecimal().abs()) ; case OP_FLOAT: return NodeValue.makeFloat( Math.abs(nv.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.abs(nv.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+nv) ; } }
public static NodeValue round(NodeValue v) { switch (classifyNumeric("round", v)) { case OP_INTEGER: return v ; case OP_DECIMAL: int sgn = v.getDecimal().signum() ; BigDecimal dec ; if ( sgn < 0 ) dec = v.getDecimal().setScale(0, BigDecimal.ROUND_HALF_DOWN) ; else dec = v.getDecimal().setScale(0, BigDecimal.ROUND_HALF_UP) ; return NodeValue.makeDecimal(dec) ; case OP_FLOAT: return NodeValue.makeFloat( Math.round(v.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.round(v.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
public static NodeValue ceiling(NodeValue v) { switch (classifyNumeric("ceiling", v)) { case OP_INTEGER: return v ; case OP_DECIMAL: BigDecimal dec = v.getDecimal().setScale( 0, BigDecimal.ROUND_CEILING) ; return NodeValue.makeDecimal(dec) ; case OP_FLOAT: return NodeValue.makeFloat( (float)Math.ceil(v.getFloat()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.ceil(v.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
public static NodeValue add(NodeValue nv1, NodeValue nv2) // F&O numeric-add { switch (classifyNumeric("add", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().add(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().add(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() + nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() + nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue numMultiply(NodeValue nv1, NodeValue nv2) // F&O numeric-multiply { switch (classifyNumeric("multiply", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().multiply(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().multiply(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() * nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() * nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue subtract(NodeValue nv1, NodeValue nv2) // F&O numeric-subtract { switch (classifyNumeric("subtract", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().subtract(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().subtract(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() - nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() - nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue multiply(NodeValue nv1, NodeValue nv2) // F&O numeric-multiply { switch (classifyNumeric("multiply", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().multiply(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().multiply(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() * nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() * nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue numAdd(NodeValue nv1, NodeValue nv2) // F&O numeric-add { switch (classifyNumeric("add", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().add(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().add(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() + nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() + nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue numSubtract(NodeValue nv1, NodeValue nv2) // F&O numeric-subtract { switch (classifyNumeric("subtract", nv1, nv2)) { case OP_INTEGER: return NodeValue.makeInteger(nv1.getInteger().subtract(nv2.getInteger())) ; case OP_DECIMAL: return NodeValue.makeDecimal(nv1.getDecimal().subtract(nv2.getDecimal())) ; case OP_FLOAT: return NodeValue.makeFloat(nv1.getFloat() - nv2.getFloat()) ; case OP_DOUBLE: return NodeValue.makeDouble(nv1.getDouble() - nv2.getDouble()) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : ("+nv1+" ," +nv2+")") ; } }
public static NodeValue unaryMinus(NodeValue nv) // F&O numeric-unary-minus { switch (classifyNumeric("unaryMinus", nv)) { case OP_INTEGER: return NodeValue.makeInteger( nv.getInteger().negate() ) ; case OP_DECIMAL: return NodeValue.makeDecimal( nv.getDecimal().negate() ) ; case OP_FLOAT: return NodeValue.makeFloat( - nv.getFloat() ) ; case OP_DOUBLE: return NodeValue.makeDouble( - nv.getDouble() ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+nv) ; } }
public static NodeValue unaryMinus(NodeValue nv) // F&O numeric-unary-minus { switch (classifyNumeric("unaryMinus", nv)) { case OP_INTEGER: return NodeValue.makeInteger( nv.getInteger().negate() ) ; case OP_DECIMAL: return NodeValue.makeDecimal( nv.getDecimal().negate() ) ; case OP_FLOAT: return NodeValue.makeFloat( - nv.getFloat() ) ; case OP_DOUBLE: return NodeValue.makeDouble( - nv.getDouble() ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+nv) ; } }