Skip to content

Cast divmod quotient to int #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,8 +2123,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 @@ -1093,6 +1093,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