Example #1
0
 public static object BitwiseAnd(bool x, object other)
 {
     if (other is bool)
     {
         return(Ops.Bool2Object(x & (bool)other));
     }
     return(IntOps.BitwiseAnd(x ? 1 : 0, other));
 }
Example #2
0
        public static object Xor(bool x, object other)
        {
            if (other is bool)
            {
                return(Ops.Bool2Object(x ^ (bool)other));
            }

            return(IntOps.Xor(x ? 1 : 0, other));
        }
 public static object ReverseMod(BigInteger x, object other)
 {
     if (other is int)
     {
         return(IntOps.Mod((int)other, x));
     }
     if (other is Complex64)
     {
         Complex64 y = (Complex64)other;
         if (y.IsZero)
         {
             throw Ops.ZeroDivisionError();
         }
         return(ComplexOps.Mod(y, Complex64.MakeReal(x)));
     }
     if (other is double)
     {
         return(FloatOps.Mod((double)other, x));
     }
     if (other is bool)
     {
         return(Mod((bool)other ? 1 : 0, x));
     }
     if (other is long)
     {
         return(Mod((long)other, x));
     }
     if (other is BigInteger)
     {
         return(Mod((BigInteger)other, x));
     }
     if (other is ExtensibleInt)
     {
         return(Mod(((ExtensibleInt)other).value, x));
     }
     if (other is ExtensibleComplex)
     {
         Complex64 y = ((ExtensibleComplex)other).value;
         if (y.IsZero)
         {
             throw Ops.ZeroDivisionError();
         }
         return(ComplexOps.Mod(y, Complex64.MakeReal(x)));
     }
     if (other is byte)
     {
         return(IntOps.Mod((int)((byte)other), x));
     }
     if (other is ExtensibleFloat)
     {
         return(FloatOps.Mod(((ExtensibleFloat)other).value, x));
     }
     return(Ops.NotImplemented);
 }
Example #4
0
        object IRichEquality.RichNotEquals(object other)
        {
            object res = IntOps.Equals(value, other);

            if (res != Ops.NotImplemented)
            {
                return(Ops.Not(res));
            }

            return(Ops.NotImplemented);
        }
Example #5
0
 public static object Multiply(bool x, object other)
 {
     if (other is bool)
     {
         return((x ? 1 : 0) * ((bool)other ? 1 : 0));
     }
     else
     {
         return(IntOps.Multiply(x ? 1 : 0, other));
     }
 }
Example #6
0
 public static object Power(bool x, object other)
 {
     if (other is bool)
     {
         return(IntOps.Power(x ? 1 : 0, (bool)other ? 1 : 0));
     }
     else
     {
         return(IntOps.Power(x ? 1 : 0, other));
     }
 }
Example #7
0
 public static object Subtract(bool x, object other)
 {
     if (other is bool)
     {
         return((x ? 1 : 0) - ((bool)other ? 1 : 0));
     }
     else
     {
         return(IntOps.Subtract(x ? 1 : 0, other));
     }
 }
Example #8
0
 public static object Add(bool x, object other)
 {
     if (other is bool)
     {
         return((x ? 1 : 0) + ((bool)other ? 1 : 0));
     }
     else
     {
         return(IntOps.Add(x ? 1 : 0, other));
     }
 }
Example #9
0
 public static object RightShift(bool x, object other)
 {
     if (other is bool)
     {
         return(IntOps.RightShift(x ? 1 : 0, (bool)other ? 1 : 0));
     }
     else
     {
         return(IntOps.RightShift(x ? 1 : 0, other));
     }
 }
Example #10
0
 public static object Divide(bool x, object other)
 {
     if (other is bool)
     {
         return(IntOps.Divide(x ? 1 : 0, (bool)other ? 1 : 0));
     }
     else
     {
         return(IntOps.Divide(x ? 1 : 0, other));
     }
 }
Example #11
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);
            }
        }
Example #12
0
 private object CompareToWorker(object other)
 {
     return(IntOps.Compare(value, other));
 }
Example #13
0
 object IRichEquality.RichEquals(object other)
 {
     return(IntOps.Equals(value, other));
 }
Example #14
0
 public virtual object Compare(object other)
 {
     return(IntOps.Compare(value, other));
 }
Example #15
0
 public static object TrueDivide(bool x, object other)
 {
     return(IntOps.TrueDivide(x ? 1 : 0, other));
 }