Skip to content

Commit 150d01d

Browse files
mrzasatompng
andauthored
Cast divmod quotient to int (#312)
* Cast divmod quotient to int * fixup! Cast divmod quotient to int --------- Co-authored-by: tomoya ishida <[email protected]>
1 parent 55d30c8 commit 150d01d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ BigDecimal_divmod(VALUE self, VALUE r)
18671867
NULLABLE_BDVALUE div, mod;
18681868

18691869
if (BigDecimal_DoDivmod(self, r, &div, &mod, false)) {
1870-
return rb_assoc_new(CheckGetValue(bdvalue_nonnullable(div)), CheckGetValue(bdvalue_nonnullable(mod)));
1870+
return rb_assoc_new(BigDecimal_to_i(CheckGetValue(bdvalue_nonnullable(div))), CheckGetValue(bdvalue_nonnullable(mod)));
18711871
}
18721872
return DoSomeOne(self,r,rb_intern("divmod"));
18731873
}

test/bigdecimal/test_bigdecimal.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,10 @@ def test_divmod
12451245

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

1248+
quotient, reminder = BigDecimal("10").divmod(3)
1249+
assert_kind_of(Integer, quotient)
1250+
assert_kind_of(BigDecimal, reminder)
1251+
12481252
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
12491253
assert_raise(ZeroDivisionError){BigDecimal("0").divmod(0)}
12501254
end

0 commit comments

Comments
 (0)