Пример #1
0
        /// <summary>
        /// Mathematical multiplication between this duration stored and the supplied
        /// duration of time (of type XSYearMonthDuration)
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to multiply by </param>
        /// <returns> New XSYearMonthDuration representing the resulting duration
        ///         after the multiplication </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence times(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public virtual ResultSequence times(ResultSequence arg)
        {
            ResultSequence convertedRS = arg;

            if (arg.size() == 1)
            {
                Item argValue = arg.first();
                if (argValue is XSDecimal)
                {
                    convertedRS = ResultSequenceFactory.create_new(new XSDouble(argValue.StringValue));
                }
            }

            XSDouble val = (XSDouble)NumericType.get_single_type(convertedRS, typeof(XSDouble));

            if (val.nan())
            {
                throw DynamicError.nan();
            }

            if (val.infinite())
            {
                throw DynamicError.overflowDateTime();
            }

            int res = (int)Math.Round(monthValue() * val.double_value());

            return(ResultSequenceFactory.create_new(new XSYearMonthDuration(res)));
        }
Пример #2
0
        /// <summary>
        /// Mathematical division between this duration stored and the supplied
        /// duration of time (of type XSDayTimeDuration)
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to divide by </param>
        /// <returns> New XSDayTimeDuration representing the resulting duration after
        ///         the division </returns>
        /// <exception cref="DynamicError"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence div(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public virtual ResultSequence div(ResultSequence arg)
        {
            if (arg.size() != 1)
            {
                DynamicError.throw_type_error();
            }

            Item at = arg.first();

            if (at is XSDouble)
            {
                XSDouble dt     = (XSDouble)at;
                double   retval = 0;

                if (dt.nan())
                {
                    throw DynamicError.nan();
                }

                if (!dt.zero())
                {
                    decimal ret = new decimal(0);

                    if (dt.infinite())
                    {
                        retval = value() / dt.double_value();
                    }
                    else
                    {
                        ret = new decimal(value());
                        ret = decimal.Divide(ret, new decimal(dt.double_value()));
                        var x = ret.ToString();
                        double.TryParse(x, out double r);
                        retval = r;
                    }
                }
                else
                {
                    throw DynamicError.overflowUnderflow();
                }

                return(ResultSequenceFactory.create_new(new XSDayTimeDuration(retval)));
            }
            else if (at is XSDecimal)
            {
                XSDecimal dt = (XSDecimal)at;

                decimal ret = new decimal(0);

                if (!dt.zero())
                {
                    ret = new decimal(value());
                    ret = decimal.Divide(ret, dt.Value);
                }
                else
                {
                    throw DynamicError.overflowUnderflow();
                }

                var x = ret.ToString();
                double.TryParse(x, out double r);
                var i = (int)r;
                return(ResultSequenceFactory.create_new(new XSDayTimeDuration(i)));
            }
            else if (at is XSDayTimeDuration)
            {
                XSDuration md = (XSDuration)at;

                decimal res = default;
                res = new decimal(this.value());
                decimal l = new decimal(md.value());
                res = decimal.Divide(res, l);

                return(ResultSequenceFactory.create_new(new XSDecimal(res)));
            }
            else
            {
                DynamicError.throw_type_error();
                return(null);                // unreach
            }
        }