Пример #1
0
        /// <summary>
        /// Mathematical integer division operator between this XSDouble and the
        /// supplied ResultSequence.
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence to perform an integer division with </param>
        /// <returns> A XSInteger consisting of the result of the mathematical integer
        ///         division. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence idiv(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence idiv(ResultSequence arg)
        {
            ResultSequence carg = convertResultSequence(arg);

            XSDouble val = (XSDouble)get_single_type(carg, typeof(XSDouble));

            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);
            }

            decimal result = new decimal((double_value() / val.double_value()));

            return(ResultSequenceFactory.create_new(new XSInteger(new BigInteger(result))));
        }
Пример #2
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)));
        }
Пример #3
0
        /// <summary>
        /// Equality comparison between this number and the supplied representation. </summary>
        /// <param name="aa">
        ///            Representation to be compared with (must currently be of type
        ///            XSDouble)
        /// </param>
        /// <returns> True if the 2 representations represent the same number. False
        ///         otherwise
        /// @since 1.1 </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean eq(AnyType aa, org.eclipse.wst.xml.xpath2.api.DynamicContext dynamicContext) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override bool eq(AnyType aa, DynamicContext dynamicContext)
        {
            ResultSequence rs  = ResultSequenceFactory.create_new(aa);
            ResultSequence crs = constructor(rs);

            if (crs.empty())
            {
                throw DynamicError.throw_type_error();
            }
            Item cat = crs.first();

            XSDouble d = (XSDouble)cat;

            if (d.nan() && nan())
            {
                return(false);
            }

            double?thatvalue = new double?(d.double_value());
            double?thisvalue = new double?(double_value());

            return(thisvalue.Equals(thatvalue));
        }
Пример #4
0
        /// <summary>
        /// Mathematical multiplication between this duration stored and the supplied
        /// duration of time (of type XSDayTimeDuration)
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to multiply by </param>
        /// <returns> New XSDayTimeDuration 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();
            }

            double res = value() * val.double_value();

            return(ResultSequenceFactory.create_new(new XSDayTimeDuration(res)));
        }
Пример #5
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
            }
        }