From 862dde5bcf894c82d8720bbe52fd22c5f49481ff 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] [ruby/bigdecimal] Correctly computing loop iterations in `BigDecimal#sqrt` (https://github.com/ruby/bigdecimal/pull/280) https://github.com/ruby/bigdecimal/commit/5843c89da4 --- 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 cb8874d31a1a1f..a473b2d42ef7e3 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