Exemplo n.º 1
0
        public static RubyArray DivMod(RubyContext /*!*/ context, object self, object other)
        {
            object div = Div(context, self, other);
            object mod = LibrarySites.Modulo(context, self, other);

            return(RubyOps.MakeArray2(div, mod));
        }
Exemplo n.º 2
0
        public static object Remainder(RubyContext /*!*/ context, object self, object other)
        {
            object modulo = LibrarySites.Modulo(context, self, other);

            if (!Protocols.IsEqual(context, modulo, 0))
            {
                // modulo is not zero
                if (RubyOps.IsTrue(LibrarySites.LessThan(context, self, 0)) && RubyOps.IsTrue(LibrarySites.GreaterThan(context, other, 0)) ||
                    RubyOps.IsTrue(LibrarySites.GreaterThan(context, self, 0)) && RubyOps.IsTrue(LibrarySites.LessThan(context, other, 0)))
                {
                    // (self is negative and other is positive) OR (self is positive and other is negative)
                    return(LibrarySites.Minus(context, modulo, other));
                }
            }
            // Either modulo is zero or self and other are not of the same sign
            return(modulo);
        }