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.
2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 |
# File 'bigdecimal.c', line 2157
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(VpCheckGetValue(div), VpCheckGetValue(mod));
}
return DoSomeOne(self,r,rb_intern("divmod"));
}
|