Skip to content

Commit 95bf47a

Browse files
authored
Fix wrong converge check in VpSqrt (#353)
1 parent f8928e2 commit 95bf47a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7261,7 +7261,7 @@ VpSqrt(Real *y, Real *x)
72617261
VpDivd(f, r, x, y); /* f = x/y */
72627262
VpAddSub(r, f, y, -1); /* r = f - y */
72637263
VpMult(f, VpConstPt5, r); /* f = 0.5*r */
7264-
if (VpIsZero(f))
7264+
if (y_prec == y->MaxPrec && VpIsZero(f))
72657265
goto converge;
72667266
VpAddSub(r, f, y, 1); /* r = y + f */
72677267
VpAsgn(y, r, 1); /* y = r */

test/bigdecimal/test_bigdecimal.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,8 @@ def test_sqrt_bigdecimal
12251225
x = BigDecimal((2**200).to_s)
12261226
assert_equal(2**100, x.sqrt(1))
12271227

1228+
assert_in_delta(BigDecimal("4.0000000000000000000125"), BigDecimal("16.0000000000000000001").sqrt(100), BigDecimal("1e-40"))
1229+
12281230
BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
12291231
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
12301232
assert_raise_with_message(FloatDomainError, "sqrt of 'NaN'(Not a Number)") { BigDecimal("NaN").sqrt(1) }

0 commit comments

Comments
 (0)