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 sqrt(NodeValue v) { switch (classifyNumeric("sqrt", v)) { case OP_INTEGER: case OP_DECIMAL: double dec = v.getDecimal().doubleValue() ; return NodeValue.makeDecimal( Math.sqrt(dec) ) ; case OP_FLOAT: // NB - returns a double return NodeValue.makeDouble( Math.sqrt(v.getDouble()) ) ; case OP_DOUBLE: return NodeValue.makeDouble( Math.sqrt(v.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
@Override public NodeValue exec(NodeValue v) { switch (XSDFuncOp.classifyNumeric("sq", v)) { case OP_INTEGER: BigInteger i = v.getInteger(); return NodeValue.makeInteger( i.pow(2) ); case OP_DECIMAL: double dec = v.getDecimal().doubleValue() ; return NodeValue.makeDecimal( Math.pow(dec, 2d)) ; case OP_FLOAT: // TODO Should squaring a float keep it a float? case OP_DOUBLE: return NodeValue.makeDouble( Math.pow(v.getDouble(), 2d) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+v) ; } }
@Override public NodeValue exec(NodeValue v) { switch (XSDFuncOp.classifyNumeric("cube", v)) { case OP_INTEGER: BigInteger i = v.getInteger(); return NodeValue.makeInteger( i.pow(3) ); case OP_DECIMAL: double dec = v.getDecimal().doubleValue() ; return NodeValue.makeDecimal( Math.pow(dec, 3d)) ; case OP_FLOAT: // TODO Should squaring a float keep it a float? case OP_DOUBLE: return NodeValue.makeDouble( Math.pow(v.getDouble(), 3d) ) ; 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 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 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 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+")") ; } }
@Override public NodeValue exec(NodeValue v1, NodeValue v2) { switch (XSDFuncOp.classifyNumeric("pow", v1)) { case OP_INTEGER: BigInteger i = v1.getInteger(); return NodeValue.makeInteger( i.pow(v2.getInteger().intValue()) ); case OP_DECIMAL: double dec = v1.getDecimal().doubleValue() ; return NodeValue.makeDecimal( Math.pow(dec, v2.getDouble())) ; case OP_FLOAT: // TODO Should raising a float to a power keep it a float? case OP_DOUBLE: return NodeValue.makeDouble( Math.pow(v1.getDouble(), v2.getDouble()) ) ; default: throw new ARQInternalErrorException("Unrecognized numeric operation : "+ v1) ; } }
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 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) ; } }