Beispiel #1
0
        public static object FxShiftLeftInternal(int a, int b)
        {
            long r = (long)a << b;

            if (r > int.MaxValue || r < int.MinValue)
            {
                return(FALSE);
            }
            return(RuntimeHelpers.Int32ToObject((int)r));
        }
Beispiel #2
0
 // improve this
 protected internal static object ToIntegerIfPossible(BigInteger i)
 {
     if (i <= int.MaxValue && i >= int.MinValue)
     {
         return(RuntimeHelpers.Int32ToObject((int)i));
     }
     else
     {
         return(i);
     }
 }
Beispiel #3
0
 protected internal static object ToIntegerIfPossible(BigInteger i)
 {
     if (i.IsInt32)
     {
         return(RuntimeHelpers.Int32ToObject((int)i));
     }
     else
     {
         return(i);
     }
 }
Beispiel #4
0
        public static object FxShiftLeftInternal(int a, int b)
        {
            long r  = (long)a << b;
            int  rr = (int)r;

            if (r != rr)
            {
                return(FALSE);
            }
            return(RuntimeHelpers.Int32ToObject(rr));
        }
Beispiel #5
0
        public static object FxMultiplyInternal(int a, int b)
        {
            long r  = (long)a * b;
            int  rr = (int)r;

            if (r != rr)
            {
                return(FALSE);
            }
            return(RuntimeHelpers.Int32ToObject(rr));
        }
Beispiel #6
0
 protected static object ConvertToObject(object ret)
 {
     if (ret is bool)
     {
         return(RuntimeHelpers.BooleanToObject((bool)ret));
     }
     else if (ret is int)
     {
         return(RuntimeHelpers.Int32ToObject((int)ret));
     }
     return(ret);
 }
Beispiel #7
0
        public static object Multiply(object first, object second)
        {
            NumberClass f = GetNumberClass(first);

            if (f == NumberClass.NotANumber)
            {
                throw new NotSupportedException("number type not supported");
            }

            NumberClass s = GetNumberClass(second);

            if (s == NumberClass.NotANumber)
            {
                throw new NotSupportedException("number type not supported");
            }

            NumberClass effective = f & s;

            switch (effective)
            {
            case NumberClass.Integer:
            {
                long result = (long)ConvertToInteger(first) * ConvertToInteger(second);
                if (result > int.MaxValue || result < int.MinValue)
                {
                    return((BigInteger)result);
                }
                else
                {
                    return(RuntimeHelpers.Int32ToObject((int)result));
                }
            }

            case NumberClass.BigInteger:
                return(ToIntegerIfPossible(ConvertToBigInteger(first) * ConvertToBigInteger(second)));

            case NumberClass.Rational:
                return(IntegerIfPossible(ConvertToRational(first) * ConvertToRational(second)));

            case NumberClass.Real:
                return(ConvertToReal(first) * ConvertToReal(second));

            case NumberClass.Complex:
                if (IsExact(first) && IsExact(second))
                {
                    return(IntegerIfPossible(ConvertToComplexFraction(first) * ConvertToComplexFraction(second)));
                }
                return(DoubleIfPossible(ConvertToComplex(first) * ConvertToComplex(second)));
            }

            throw new NotSupportedException("number type not supported");
        }
Beispiel #8
0
        public static object Multiply(object first, object second)
        {
            NumberClass f = GetNumberClass(first);
            NumberClass s = GetNumberClass(second);

            NumberClass effective = f & s;

            switch (effective)
            {
            case NumberClass.Integer:
            {
                long result  = (long)ConvertToInteger(first) * ConvertToInteger(second);
                int  iresult = (int)result;
                if (result != iresult)
                {
                    return((BigInteger)result);
                }
                else
                {
                    return(RuntimeHelpers.Int32ToObject(iresult));
                }
            }

            case NumberClass.BigInteger:
                return(ToIntegerIfPossible(ConvertToBigInteger(first) * ConvertToBigInteger(second)));

            case NumberClass.Rational:
                return(IntegerIfPossible(ConvertToRational(first) * ConvertToRational(second)));

            case NumberClass.Real:
                return(ConvertToReal(first) * ConvertToReal(second));

            case NumberClass.Complex:
                if (IsExact(first) && IsExact(second))
                {
                    return(IntegerIfPossible(ConvertToComplexFraction(first) * ConvertToComplexFraction(second)));
                }
                return(DoubleIfPossible(ConvertToComplex(first) * ConvertToComplex(second)));
            }

            RaiseNumberTypeNotSupported();
            return(null);
        }