Esempio n. 1
0
 private object CompareToWorker(object other)
 {
     return(IntOps.Compare(value, other));
 }
Esempio n. 2
0
        public static object Compare(BigInteger x, object y)
        {
            if (y == null)
            {
                return(1);
            }

            int intVal;

            if (y is int)
            {
                if (x.AsInt32(out intVal))
                {
                    return(IntOps.Compare(intVal, y));
                }
            }
            else if (y is ExtensibleInt)
            {
                if (x.AsInt32(out intVal))
                {
                    return(IntOps.Compare(intVal, ((ExtensibleInt)y).value));
                }
            }
            else if (y is double)
            {
                double dbl = x.ToFloat64();
                return(FloatOps.Compare(dbl, y));
            }
            else if (y is ExtensibleFloat)
            {
                double dbl = x.ToFloat64();
                return(FloatOps.Compare(dbl, ((ExtensibleFloat)y).value));
            }
            else if (y is bool)
            {
                if (x.AsInt32(out intVal))
                {
                    return(IntOps.Compare(intVal, ((bool)y) ? 1 : 0));
                }
            }
            else if (y is decimal)
            {
                double dbl = x.ToFloat64();
                return(FloatOps.Compare(dbl, y));
            }

            Conversion conv;
            BigInteger bi = Converter.TryConvertToBigInteger(y, out conv);

            if (conv == Conversion.None)
            {
                object res = Ops.GetDynamicType(y).Coerce(y, x);
                if (res != Ops.NotImplemented && !(res is OldInstance))
                {
                    return(Ops.Compare(((Tuple)res)[1], ((Tuple)res)[0]));
                }
                return(Ops.NotImplemented);
            }

            BigInteger diff = x - bi;

            if (diff == 0)
            {
                return(0);
            }
            else if (diff < 0)
            {
                return(-1);
            }
            else
            {
                return(1);
            }
        }
Esempio n. 3
0
 public virtual object Compare(object other)
 {
     return(IntOps.Compare(value, other));
 }