summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-09 14:30:30 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-09 14:30:30 +0000
commit03ad923cdd130bd522e7b25e6f3958b3118aae01 (patch)
tree87de5d985e1093cd9b0b3f79fd772a383b5cee5d /ext/bigdecimal
parentb4f90b236c56601a1d112af7c116fc9ef80703d6 (diff)
* ext/bigdecimal/bigdecimal.c (BigDecimal_DoDivmod): fix precision.
[ruby-core:17472][ruby-dev:35372][ruby-dev:40105][ruby-dev:40358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 8e85fdf1f8f..67622ea5eb6 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -970,8 +970,8 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
return Qtrue;
}
- mx = a->Prec;
- if(mx<b->Prec) mx = b->Prec;
+ mx = a->Prec+abs(a->exponent);
+ if(mx<b->Prec+abs(b->exponent)) mx = b->Prec+abs(b->exponent);
mx =(mx + 1) * VpBaseFig();
GUARD_OBJ(c,VpCreateRbObject(mx, "0"));
GUARD_OBJ(res,VpCreateRbObject((mx+1) * 2 +(VpBaseFig() + 1), "#0"));
@@ -983,6 +983,7 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
VpAddSub(c,a,res,-1);
if(!VpIsZero(c) && (VpGetSign(a)*VpGetSign(b)<0)) {
VpAddSub(res,d,VpOne(),-1);
+ GUARD_OBJ(d,VpCreateRbObject(GetAddSubPrec(c, b)*(VpBaseFig() + 1), "0"));
VpAddSub(d ,c,b, 1);
*div = res;
*mod = d;