Ejemplo n.º 1
0
        public override RArray DivMod(object o)
        {
            RBignum z;
            RBignum y = divmod(o, out z);

            return(RArray.AssocNew(ruby, y.Normalize, z.Normalize));
        }
Ejemplo n.º 2
0
 public override RArray Coerce(object y)
 {
     if (y is int || y is long || y is RFixnum)
     {
         return(RArray.AssocNew(ruby, to_big(ruby, y), this));
     }
     throw new eTypeError("Can't create " + ruby.ClassOf(y).Name + " to Bignum");
 }
Ejemplo n.º 3
0
 public virtual RArray Coerce(object o)
 {
     if (ruby.ClassOf(o) == Class)
     {
         return(RArray.AssocNew(ruby, Instanciate(o), this));
     }
     return(RArray.AssocNew(ruby, RFloat.Float(ruby, o), ToFloat()));
 }
Ejemplo n.º 4
0
        public override RArray ToArray()
        {
            ArrayList a = new ArrayList();

            lock (hash.SyncRoot)
            {
                foreach (DictionaryEntry ent in hash)
                {
                    a.Add(RArray.AssocNew(ruby, ent.Key, ent.Value));
                }
            }
            return(new RArray(ruby, a));
        }
Ejemplo n.º 5
0
        public override RArray DivMod(object o)
        {
            int y;

            if (o is int)
            {
                y = (int)o;
            }
            else if (o is RFixnum)
            {
                y = (int)((RFixnum)o).iVal;
            }
            else
            {
                return((RArray)CoerceBin(o));
            }
            int mod;
            int d = divmod(y, out mod);

            return(RArray.AssocNew(ruby, new RFixnum(ruby, d), new RFixnum(ruby, mod)));
        }
Ejemplo n.º 6
0
        public override RArray DivMod(object o)
        {
            double y;

            if (o is int)
            {
                y = (int)o;
            }
            else if (o is long)
            {
                y = (long)o;
            }
            else if (o is RFixnum)
            {
                y = ((RFixnum)o).ToLong();
            }
            else if (o is double)
            {
                y = (double)o;
            }
            else if (o is RFloat)
            {
                y = ((RFloat)o).dVal;
            }
            else if (o is RBignum)
            {
                y = ((RBignum)o).Big2Dbl();
            }
            else
            {
                return((RArray)CoerceBin(o));
            }
            if (y == 0.0)
            {
                throw new DivideByZeroException("divided by 0");
            }
            return(RArray.AssocNew(ruby, new RFloat(ruby, dVal / y), Modulo(y)));
        }