Search in sources :

Example 11 with XSFloat

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

the class TestBugs method testNegativeZeroFloat.

public void testNegativeZeroFloat() throws Exception {
    // Bug 279406
    bundle = Platform.getBundle("org.w3c.xqts.testsuite");
    URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = "-(xs:float('0'))";
    compileXPath(xpath);
    ResultSequence rs = evaluate(domDoc);
    XSFloat result = (XSFloat) rs.first();
    String actual = result.getStringValue();
    assertEquals("-0", actual);
}
Also used : XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) URL(java.net.URL)

Example 12 with XSFloat

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

the class FsPlus method convert_args.

/**
 * Convert and promote arguments for operation.
 *
 * @param args
 *            input arguments.
 * @param sc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of conversion.
 */
private static Collection convert_args(Collection args) throws DynamicError {
    Collection result = new ArrayList();
    // Keep track of numeric types for promotion
    boolean has_float = false;
    boolean has_double = false;
    // atomize arguments
    for (Iterator i = args.iterator(); i.hasNext(); ) {
        org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize((org.eclipse.wst.xml.xpath2.api.ResultSequence) i.next());
        if (rs.empty())
            return new ArrayList();
        if (rs.size() > 1)
            throw new DynamicError(TypeError.invalid_type(null));
        AnyType arg = (AnyType) rs.item(0);
        if (arg instanceof XSUntypedAtomic) {
            arg = new XSDouble(arg.getStringValue());
        }
        if (arg instanceof XSDouble)
            has_double = true;
        if (arg instanceof XSFloat)
            has_float = true;
        result.add(ResultBuffer.wrap(arg));
    }
    if (has_double)
        has_float = false;
    if (has_double || has_float) {
        Collection result2 = new ArrayList();
        // promote arguments
        for (Iterator i = result.iterator(); i.hasNext(); ) {
            org.eclipse.wst.xml.xpath2.api.ResultSequence rs = (org.eclipse.wst.xml.xpath2.api.ResultSequence) i.next();
            Item arg = rs.item(0);
            if (has_double && (arg instanceof XSFloat)) {
                arg = new XSDouble(((XSFloat) arg).float_value());
            } else if (has_double && (arg instanceof XSDecimal)) {
                arg = new XSDouble(((XSDecimal) arg).getValue().doubleValue());
            } else if (has_float && (arg instanceof XSDecimal)) {
                arg = new XSFloat(((XSDecimal) arg).getValue().floatValue());
            }
            result2.add(arg);
        }
        return result2;
    }
    return result;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ArrayList(java.util.ArrayList) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) Item(org.eclipse.wst.xml.xpath2.api.Item) XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) Iterator(java.util.Iterator) Collection(java.util.Collection) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 13 with XSFloat

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

the class XSFloat method minus.

/**
 * Mathematical subtraction operator between this XSFloat and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform a subtraction with
 * @return A XSFloat consisting of the result of the mathematical
 *         subtraction.
 */
public ResultSequence minus(ResultSequence arg) throws DynamicError {
    ResultSequence carg = constructor(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 14 with XSFloat

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

the class XSFloat method idiv.

/**
 * Mathematical integer division operator between this XSFloat 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);
    XSFloat val = (XSFloat) get_single_type(carg, XSFloat.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 = BigDecimal.valueOf((new Float((float_value() / val.float_value()))).longValue());
    return ResultSequenceFactory.create_new(new XSInteger(result.toBigInteger()));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) BigDecimal(java.math.BigDecimal)

Example 15 with XSFloat

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

the class XSFloat method gt.

/**
 * Comparison between this number and the supplied representation.
 *
 * @param arg
 *            The datatype to compare with
 * @return True if the supplied representation is a smaller number than the
 *         one stored. False otherwise
 * @throws DynamicError
 */
public boolean gt(AnyType arg, DynamicContext context) throws DynamicError {
    Item carg = convertArg(arg);
    XSFloat val = (XSFloat) get_single_type(carg, XSFloat.class);
    return float_value() > val.float_value();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

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