Search in sources :

Example 6 with XSFloat

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat in project webtools.sourceediting by eclipse.

the class XSFloat method plus.

/**
 * Mathematical addition operator between this XSFloat and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform an addition with
 * @return A XSFloat 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 XSFloat))
        DynamicError.throw_type_error();
    XSFloat val = (XSFloat) at;
    return ResultSequenceFactory.create_new(new XSFloat(float_value() + val.float_value()));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 7 with XSFloat

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat in project webtools.sourceediting by eclipse.

the class XSFloat method eq.

/**
 * Equality comparison between this number and the supplied representation.
 * @param aa
 *            The datatype to compare with
 *
 * @return True if the two representations are of the same number. False
 *         otherwise
 * @throws DynamicError
 */
public boolean eq(AnyType aa, DynamicContext dynamicContext) throws DynamicError {
    Item carg = convertArg(aa);
    if (!(carg instanceof XSFloat))
        DynamicError.throw_type_error();
    XSFloat f = (XSFloat) carg;
    if (nan() && f.nan()) {
        return false;
    }
    Float thatvalue = new Float(f.float_value());
    Float thisvalue = new Float(float_value());
    return thisvalue.equals(thatvalue);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 8 with XSFloat

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat in project webtools.sourceediting by eclipse.

the class XSFloat method times.

/**
 * Mathematical multiplication operator between this XSFloat and the
 * supplied ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform a multiplication with
 * @return A XSFloat consisting of the result of the mathematical
 *         multiplication.
 */
public ResultSequence times(ResultSequence arg) throws DynamicError {
    ResultSequence carg = constructor(arg);
    XSFloat val = (XSFloat) get_single_type(carg, XSFloat.class);
    return ResultSequenceFactory.create_new(new XSFloat(float_value() * val.float_value()));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 9 with XSFloat

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat 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 10 with XSFloat

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat in project webtools.sourceediting by eclipse.

the class XSFloat method div.

/**
 * Mathematical division operator between this XSFloat and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform a division with
 * @return A XSFloat consisting of the result of the mathematical division.
 */
public ResultSequence div(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    XSFloat val = (XSFloat) get_single_type(carg, XSFloat.class);
    return ResultSequenceFactory.create_new(new XSFloat(float_value() / val.float_value()));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)10 Item (org.eclipse.wst.xml.xpath2.api.Item)6 XSFloat (org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat)6 Iterator (java.util.Iterator)5 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)5 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)4 TypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter)4 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)3 ComparableTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter)2 ScalarTypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter)2 BigDecimal (java.math.BigDecimal)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 XSModel (org.apache.xerces.xs.XSModel)1 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)1 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)1 XSDecimal (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal)1 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)1 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)1