Skip to content

Commit

Permalink
Cast divmod quotient to int
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzasa committed Feb 4, 2025
1 parent a015c8b commit 7a86e95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2172,8 +2172,8 @@ BigDecimal_divmod(VALUE self, VALUE r)
Real *div = NULL, *mod = NULL;

if (BigDecimal_DoDivmod(self, r, &div, &mod)) {
SAVE(div); SAVE(mod);
return rb_assoc_new(VpCheckGetValue(div), VpCheckGetValue(mod));
SAVE(div); SAVE(mod);
return rb_assoc_new(BigDecimal_to_i(VpCheckGetValue(div)), VpCheckGetValue(mod));
}
return DoSomeOne(self,r,rb_intern("divmod"));
}
Expand Down
4 changes: 4 additions & 0 deletions test/bigdecimal/test_bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ def test_divmod

assert_equal([0, 0], BigDecimal("0").divmod(2))

quotient, reminder = BigDecimal("10").divmod(3)
assert_kind_of(Integer, quotient)
assert_kind_of(BigDecimal, reminder)

BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
assert_raise(ZeroDivisionError){BigDecimal("0").divmod(0)}
end
Expand Down

0 comments on commit 7a86e95

Please sign in to comment.