Skip to content
Merged
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
5 changes: 2 additions & 3 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1905,18 +1905,17 @@ BigDecimal_div2(VALUE self, VALUE b, VALUE n)
/* div in BigDecimal sense */
ix = check_int_precision(n);

if (ix == 0) ix = VpGetPrecLimit();

av = GetBDValueMust(self);
bv = GetBDValueWithPrecMust(b, GetCoercePrec(av.real, ix));

if (ix == 0) {
ssize_t a_prec, b_prec;
ssize_t a_prec, b_prec, limit = VpGetPrecLimit();
VpCountPrecisionAndScale(av.real, &a_prec, NULL);
VpCountPrecisionAndScale(bv.real, &b_prec, NULL);
ix = ((a_prec > b_prec) ? a_prec : b_prec) + BIGDECIMAL_DOUBLE_FIGURES;
if (2 * BIGDECIMAL_DOUBLE_FIGURES > ix)
ix = 2 * BIGDECIMAL_DOUBLE_FIGURES;
if (limit && limit < ix) ix = limit;
}

// Needs to calculate 1 extra digit for rounding.
Expand Down
9 changes: 9 additions & 0 deletions test/bigdecimal/test_bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,15 @@ def test_arithmetic_operation_with_limit
end
end

def test_div_with_huge_limit
BigDecimal.save_limit do
x, y = BigDecimal(2), BigDecimal(3)
div = x / y
BigDecimal.limit(1000)
assert_equal(div, x / y)
end
end

def test_div_mod_rem_operation_with_limit
x = -(9 ** 100)
y = 7 ** 100
Expand Down
Loading