instance method
Integer#divmod
(::Integer) -> [ ::Integer, ::Integer ]
(::Float) -> [ ::Integer, ::Float ]
(::Rational) -> [ ::Integer, ::Rational ]
(::Numeric) -> [ ::Numeric, ::Numeric ]
divmod(other) → array
numeric.c
View on GitHub ↗
VALUE
rb_int_divmod(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_divmod(x, y);
}
else if (RB_BIGNUM_TYPE_P(x)) {
return rb_big_divmod(x, y);
}
return Qnil;
}
Returns a 2-element array [q, r], where
Example
q = (self/other).floor # Quotient r = self % other # Remainder
Examples:
Example
11.divmod(4) # => [2, 3] 11.divmod(-4) # => [-3, -1] -11.divmod(4) # => [-3, 1] -11.divmod(-4) # => [2, -3] 12.divmod(4) # => [3, 0] 12.divmod(-4) # => [-3, 0] -12.divmod(4) # => [-3, 0] -12.divmod(-4) # => [3, 0] 13.divmod(4.0) # => [3, 1.0] 13.divmod(Rational(4, 1)) # => [3, (1/1)]