CreateRangeError() public static method

public static CreateRangeError ( string message ) : Exception
message string
return System.Exception
Exemplo n.º 1
0
        public int ToInt32()
        {
            int result;

            if (IsFixnum)
            {
                result = _fixnum;
            }
            else if (!_bignum.AsInt32(out result))
            {
                throw RubyExceptions.CreateRangeError("Bignum too big to convert into 32-bit signed integer");
            }
            return(result);
        }
Exemplo n.º 2
0
        public uint ToUInt32Unchecked()
        {
            if (IsFixnum)
            {
                return(unchecked ((uint)_fixnum));
            }

            try{
                return(Convert.ToUInt32(_bignum));
            }catch (OverflowException)
            {
                throw RubyExceptions.CreateRangeError("bignum too big to convert into 32-bit unsigned integer");
            }
        }
Exemplo n.º 3
0
        public uint ToUInt32Unchecked()
        {
            if (IsFixnum)
            {
                return(unchecked ((uint)_fixnum));
            }

            uint u;

            if (_bignum.AsUInt32(out u))
            {
                return(u);
            }
            throw RubyExceptions.CreateRangeError("bignum too big to convert into 32-bit unsigned integer");
        }
Exemplo n.º 4
0
        public int ToInt32()
        {
            int result;

            if (IsFixnum)
            {
                result = _fixnum;
            }
            try
            {
                result = Convert.ToInt32(_bignum);
            }catch (OverflowException)
            {
                throw RubyExceptions.CreateRangeError("Bignum too big to convert into 32-bit signed integer");
            }
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Like CastToInteger, but converts the result to a Fixnum
        /// </summary>
        public static int CastToFixnum(RubyContext /*!*/ context, object obj)
        {
            if (obj == null)
            {
                throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer");
            }

            int        fixnum;
            BigInteger bignum;

            CastToInteger(context, obj, out fixnum, out bignum);
            if ((object)bignum != null && !bignum.AsInt32(out fixnum))
            {
                throw RubyExceptions.CreateRangeError("bignum too big to convert into `long'");
            }

            return(fixnum);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts an Integer to a Fixnum.
        /// Don't call any conversion methods--just handles Fixnum & Bignum
        /// </summary>
        /// <param name="value"></param>
        /// <returns>true if value is an Integer, false otherwise</returns>
        /// <exception cref="ArgumentOutOfRangeException">Throws a RangeError if value is a
        /// BigInteger but can't be converted to a Fixnum</exception>
        public static bool IntegerAsFixnum(object value, out int result)
        {
            if (value is int)
            {
                result = (int)value;
                return(true);
            }

            var bignum = value as BigInteger;

            if ((object)bignum != null)
            {
                if (!bignum.AsInt32(out result))
                {
                    throw RubyExceptions.CreateRangeError("bignum too big to convert into `long'");
                }
                return(true);
            }

            result = 0;
            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Like CastToInteger, but converts the result to an unsigned int.
        /// </summary>
        public static ulong CastToUInt64Unchecked(RubyContext /*!*/ context, object obj)
        {
            if (obj == null)
            {
                throw RubyExceptions.CreateTypeError("no implicit conversion from nil to integer");
            }

            int        fixnum;
            BigInteger bignum;

            CastToInteger(context, obj, out fixnum, out bignum);
            if ((object)bignum != null)
            {
                ulong u;
                if (bignum.AsUInt64(out u))
                {
                    return(u);
                }
                throw RubyExceptions.CreateRangeError("bignum too big to convert into `quad long'");
            }

            return(unchecked ((ulong)fixnum));
        }