Exemplo n.º 1
0
        protected internal static bool needsStringComparison(AnyType item, AnyType at)
        {
            if (item is NumericType)
            {
                if (at is XSFloat)
                {
                    XSFloat f = (XSFloat)at;
                    if (f.nan())
                    {
                        return(true);
                    }
                }

                if (at is XSDouble)
                {
                    XSDouble d = (XSDouble)at;
                    if (d.nan())
                    {
                        return(true);
                    }
                }
            }

            if (at is XSString)
            {
                return(true);
            }

            if (at is XSUntypedAtomic)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Absolute value operation.
        /// </summary>
        /// <param name="arg">
        ///            Result from the expressions evaluation. </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of fn:abs operation. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence fn_abs(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public static ResultSequence fn_abs(ResultSequence arg)
        {
            // sanity chex
            NumericType nt = get_single_numeric_arg(arg);

            // empty arg
            if (nt == null)
            {
                return(ResultBuffer.EMPTY);
            }

            if (nt is XSDouble)
            {
                XSDouble dat = (XSDouble)nt;
                if (dat.zero() || dat.negativeZero())
                {
                    return(new XSDouble("0"));
                }
                if (dat.infinite())
                {
                    return(new XSDouble(double.PositiveInfinity));
                }
            }

            if (nt is XSFloat)
            {
                XSFloat dat = (XSFloat)nt;
                if (dat.zero() || dat.negativeZero())
                {
                    return(new XSFloat((float)0));
                }
                if (dat.infinite())
                {
                    return(new XSFloat(float.PositiveInfinity));
                }
            }


            return(nt.abs());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convert and promote arguments for operation.
        /// </summary>
        /// <param name="args">
        ///            input arguments. </param>
        /// <param name="sc"> </param>
        /// <exception cref="DynamicError">
        ///             Dynamic error. </exception>
        /// <returns> Result of conversion. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static java.util.Collection convert_args(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        private static ICollection convert_args(ICollection args)
        {
            var result = new ArrayList();

            // Keep track of numeric types for promotion
            bool has_float  = false;
            bool has_double = false;

            // atomize arguments
            for (IEnumerator i = args.GetEnumerator(); i.MoveNext();)
            {
                ResultSequence rs = FnData.atomize((ResultSequence)i.Current);

                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 is XSUntypedAtomic)
                {
                    arg = new XSDouble(arg.StringValue);
                }

                if (arg is XSDouble)
                {
                    has_double = true;
                }
                if (arg is XSFloat)
                {
                    has_float = true;
                }
                result.Add(ResultBuffer.wrap(arg));
            }

            if (has_double)
            {
                has_float = false;
            }

            if (has_double || has_float)
            {
                var result2 = new ArrayList();

                // promote arguments
                for (IEnumerator i = result.GetEnumerator(); i.MoveNext();)
                {
                    ResultSequence rs = (ResultSequence)i.Current;

                    Item arg = rs.item(0);

                    if (has_double && (arg is XSFloat))
                    {
                        arg = new XSDouble(((XSFloat)arg).float_value());
                    }
                    else if (has_double && (arg is XSDecimal))
                    {
                        arg = new XSDouble(((XSDecimal)arg).double_value());
                    }
                    else if (has_float && (arg is XSDecimal))
                    {
                        arg = new XSFloat((float)((XSDecimal)arg).double_value());
                    }
                    result2.Add(arg);
                }
                return(result2);
            }

            return(result);
        }