aboutsummaryrefslogtreecommitdiffstats
path: root/ext/bigdecimal/bigdecimal.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-21 12:37:46 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-21 12:37:46 +0000
commitff3e585014f6388636fbc2a57800fadce3b99219 (patch)
treed1a130d04121e11d11d9e4663db557f5c20a3bba /ext/bigdecimal/bigdecimal.c
parentd1d737ae5751f07a55c80a6761fa4f126e7d6f1f (diff)
downloadruby-ff3e585014f6388636fbc2a57800fadce3b99219.tar.gz
* ext/bigdecimal/bigdecimal.c (BigDecimal_sqrt): Fix the precision of
the result BigDecimal of sqrt. [Bug #5266] [ruby-dev:44450] * test/bigdecimal/test_bigdecimal.rb: add tests for the above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/bigdecimal.c')
-rw-r--r--ext/bigdecimal/bigdecimal.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index e82ac38189..53efafd24b 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -1591,10 +1591,10 @@ BigDecimal_sqrt(VALUE self, VALUE nFig)
size_t mx, n;
GUARD_OBJ(a, GetVpValue(self, 1));
- mx = a->Prec *(VpBaseFig() + 1);
+ mx = a->Prec * (VpBaseFig() + 1);
- n = GetPositiveInt(nFig) + VpDblFig() + 1;
- if(mx <= n) mx = n;
+ n = GetPositiveInt(nFig) + VpDblFig() + BASE_FIG;
+ if (mx <= n) mx = n;
GUARD_OBJ(c, VpCreateRbObject(mx, "0"));
VpSqrt(c, a);
return ToValue(c);
@@ -5654,6 +5654,7 @@ VpSqrt(Real *y, Real *x)
n = (SIGNED_VALUE)y->MaxPrec;
if (x->MaxPrec > (size_t)n) n = (ssize_t)x->MaxPrec;
+
/* allocate temporally variables */
f = VpAlloc(y->MaxPrec * (BASE_FIG + 2), "#1");
r = VpAlloc((n + n) * (BASE_FIG + 2), "#1");
@@ -5691,8 +5692,7 @@ VpSqrt(Real *y, Real *x)
if (VpIsZero(f)) goto converge;
VpAddSub(r, f, y, 1); /* r = y + f */
VpAsgn(y, r, 1); /* y = r */
- if (f->exponent <= prec) goto converge;
- } while(++nr < n);
+ } while (++nr < n);
#ifdef BIGDECIMAL_DEBUG
if (gfDebug) {