Method: BigDecimal#divmod
- Defined in:
- bigdecimal.c
#divmod(r) ⇒ Object
divmod(value)
Divides by the specified value, and returns the quotient and modulus as BigDecimal numbers. The quotient is rounded towards negative infinity.
For example:
require 'bigdecimal'
a = BigDecimal("42")
b = BigDecimal("9")
q, m = a.divmod(b)
c = q * b + m
a == c #=> true
The quotient q is (a/b).floor, and the modulus is the amount that must be added to q * b to get a.
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 |
# File 'bigdecimal.c', line 1655
static VALUE
BigDecimal_divmod(VALUE self, VALUE r)
{
ENTER(5);
Real *div = NULL, *mod = NULL;
if (BigDecimal_DoDivmod(self, r, &div, &mod)) {
SAVE(div); SAVE(mod);
return rb_assoc_new(ToValue(div), ToValue(mod));
}
return DoSomeOne(self,r,rb_intern("divmod"));
}
|