From 5843c89da40b743225de2a822a6d4030848d972a Mon Sep 17 00:00:00 2001 From: z2 <88509734+z2-2z@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:31:52 +0100 Subject: [PATCH] Correctly computing loop iterations in `BigDecimal#sqrt` (#280) --- ext/bigdecimal/bigdecimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 0595726c..0550e6e3 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -7230,7 +7230,7 @@ VpSqrt(Real *y, Real *x) y->MaxPrec = Min((size_t)n , y_prec); f->MaxPrec = y->MaxPrec + 1; n = (SIGNED_VALUE)(y_prec * BASE_FIG); - if (n < (SIGNED_VALUE)maxnr) n = (SIGNED_VALUE)maxnr; + if (n > (SIGNED_VALUE)maxnr) n = (SIGNED_VALUE)maxnr; /* * Perform: y_{n+1} = (y_n - x/y_n) / 2