use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class FnSum method sum.
/**
* Sum operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:sum operation.
*/
public static ResultSequence sum(ResultSequence arg, AnyAtomicType zero) throws DynamicError {
if (arg.empty())
return ResultSequenceFactory.create_new(zero);
MathPlus total = null;
TypePromoter tp = new ScalarTypePromoter();
tp.considerSequence(arg);
for (Iterator i = arg.iterator(); i.hasNext(); ) {
AnyAtomicType conv = tp.promote((AnyType) i.next());
if (conv == null) {
conv = zero;
}
if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
}
if (total == null) {
total = (MathPlus) conv;
} else {
total = (MathPlus) total.plus(ResultSequenceFactory.create_new(conv)).first();
}
}
return ResultSequenceFactory.create_new((AnyType) total);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method gt.
/**
* Comparison between this number and the supplied representation.
*
* @param arg
* Representation to be compared with (must currently be of type
* XSDouble)
* @return True if the supplied type represents a number smaller than this
* one stored. False otherwise
*/
public boolean gt(AnyType arg, DynamicContext context) throws DynamicError {
Item carg = convertArg(arg);
XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
return double_value() > val.double_value();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method mod.
/**
* Mathematical modulus operator between this XSDouble and the supplied
* ResultSequence.
*
* @param arg
* The ResultSequence to perform a modulus with
* @return A XSDouble consisting of the result of the mathematical modulus.
*/
public ResultSequence mod(ResultSequence arg) throws DynamicError {
ResultSequence carg = convertResultSequence(arg);
XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
return ResultSequenceFactory.create_new(new XSDouble(double_value() % val.double_value()));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method idiv.
/**
* Mathematical integer division operator between this XSDouble and the
* supplied ResultSequence.
*
* @param arg
* The ResultSequence to perform an integer division with
* @return A XSInteger consisting of the result of the mathematical integer
* division.
*/
public ResultSequence idiv(ResultSequence arg) throws DynamicError {
ResultSequence carg = convertResultSequence(arg);
XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
if (this.nan() || val.nan())
throw DynamicError.numeric_overflow("Dividend or divisor is NaN");
if (this.infinite())
throw DynamicError.numeric_overflow("Dividend is infinite");
if (val.zero())
throw DynamicError.div_zero(null);
BigDecimal result = new BigDecimal((double_value() / val.double_value()));
return ResultSequenceFactory.create_new(new XSInteger(result.toBigInteger()));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method plus.
// math
/**
* Mathematical addition operator between this XSDouble and the supplied
* ResultSequence.
*
* @param arg
* The ResultSequence to perform an addition with
* @return A XSDouble consisting of the result of the mathematical addition.
*/
public ResultSequence plus(ResultSequence arg) throws DynamicError {
ResultSequence carg = convertResultSequence(arg);
Item at = get_single_arg(carg);
if (!(at instanceof XSDouble))
DynamicError.throw_type_error();
XSDouble val = (XSDouble) at;
return ResultSequenceFactory.create_new(new XSDouble(double_value() + val.double_value()));
}
Aggregations