Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new result sequence consisting of the retrievable double number
        /// in the supplied result sequence
        /// </summary>
        /// <param name="arg">
        ///            The result sequence from which to extract the double number. </param>
        /// <exception cref="DynamicError"> </exception>
        /// <returns> A new result sequence consisting of the double number supplied. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence constructor(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence constructor(ResultSequence arg)
        {
            if (arg.empty())
            {
                return(ResultBuffer.EMPTY);
            }

            Item aat = arg.first();

            if (aat is XSDuration || aat is CalendarType || aat is XSBase64Binary || aat is XSHexBinary || aat is XSAnyURI)
            {
                throw DynamicError.invalidType();
            }

            if (!isCastable(aat))
            {
                throw DynamicError.cant_cast(null);
            }

            XSDouble d = castDouble(aat);

            if (d == null)
            {
                throw DynamicError.cant_cast(null);
            }

            return(d);
        }
Ejemplo n.º 2
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))));
        }
Ejemplo n.º 3
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)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Mathematical modulus operator between this XSDouble and the supplied
        /// ResultSequence.
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence to perform a modulus with </param>
        /// <returns> A XSDouble consisting of the result of the mathematical modulus. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence mod(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence mod(ResultSequence arg)
        {
            ResultSequence carg = convertResultSequence(arg);

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

            return(ResultSequenceFactory.create_new(new XSDouble(double_value() % val.double_value())));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Comparison between this number and the supplied representation. Currently
        /// no numeric type promotion exists so the supplied representation must be
        /// of type XSDouble.
        /// </summary>
        /// <param name="arg">
        ///            Representation to be compared with (must currently be of type
        ///            XSDouble) </param>
        /// <returns> True if the supplied type represents a number greater than this
        ///         one stored. False otherwise </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean lt(AnyType arg, org.eclipse.wst.xml.xpath2.api.DynamicContext context) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override bool lt(AnyType arg, DynamicContext context)
        {
            Item carg = convertArg(arg);

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

            return(double_value() < val.double_value());
        }
Ejemplo n.º 6
0
        // math
        /// <summary>
        /// Mathematical addition operator between this XSDouble and the supplied
        /// ResultSequence.
        /// </summary>
        /// <param name="arg">
        ///            The ResultSequence to perform an addition with </param>
        /// <returns> A XSDouble consisting of the result of the mathematical addition. </returns>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.eclipse.wst.xml.xpath2.api.ResultSequence plus(org.eclipse.wst.xml.xpath2.api.ResultSequence arg) throws org.eclipse.wst.xml.xpath2.processor.DynamicError
        public override ResultSequence plus(ResultSequence arg)
        {
            ResultSequence carg = convertResultSequence(arg);
            Item           at   = get_single_arg(carg);

            if (!(at is XSDouble))
            {
                DynamicError.throw_type_error();
            }
            XSDouble val = (XSDouble)at;

            return(ResultSequenceFactory.create_new(new XSDouble(double_value() + val.double_value())));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Mathematical division between this duration stored and the supplied
        /// duration of time (of type XSYearMonthDuration)
        /// </summary>
        /// <param name="arg">
        ///            The duration of time to divide by </param>
        /// <returns> New XSYearMonthDuration 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;

                int ret = 0;

                if (!dt.zero())
                {
                    ret = (int)Math.Round(monthValue() / dt.double_value());
                }

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

                int ret = 0;

                if (!dt.zero())
                {
                    ret = (int)Math.Round(monthValue() / dt.Value);
                }

                return(ResultSequenceFactory.create_new(new XSYearMonthDuration(ret)));
            }
            else if (at is XSYearMonthDuration)
            {
                XSYearMonthDuration md = (XSYearMonthDuration)at;

                double res = (double)monthValue() / md.monthValue();

                return(ResultSequenceFactory.create_new(new XSDecimal(new decimal(res))));
            }
            else
            {
                DynamicError.throw_type_error();
                return(null);                // unreach
            }
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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)));
        }
Ejemplo n.º 10
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
            }
        }