Search in sources :

Example 6 with XSDouble

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);
}
Also used : XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) ScalarTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) Iterator(java.util.Iterator) TypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter) ScalarTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)

Example 7 with XSDouble

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();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 8 with XSDouble

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()));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 9 with XSDouble

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()));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) BigDecimal(java.math.BigDecimal)

Example 10 with XSDouble

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()));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)17 Item (org.eclipse.wst.xml.xpath2.api.Item)12 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)12 Iterator (java.util.Iterator)9 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)6 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)6 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)5 XSFloat (org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat)5 Collection (java.util.Collection)4 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)4 XSUntypedAtomic (org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)4 TypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter)4 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)3 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)2 ComparableTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter)2 ScalarTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1