summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-03 09:12:41 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-03 09:12:41 +0000
commitb1809bcff1c00a786fd8d5a98147cacf348c1b75 (patch)
treef4e69bdf809c3cc1deda20620f6d88d2890e745d /ext
parent4fcb855ff382db0f0f8d849b5af48a652bd3494a (diff)
merges r26626 and r26627 from trunk into ruby_1_9_1. This fixes #3159.
-- * ext/bigdecimal/bigdecimal.c (BigDecimal_DoDivmod): fix precision. [ruby-core:17472][ruby-dev:35372][ruby-dev:40105][ruby-dev:40358] -- * ext/bigdecimal/bigdecimal.c (BigDecimal_divide): fix precision too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@27597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/bigdecimal/bigdecimal.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 776c0ae491..42ec26e706 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -951,7 +951,9 @@ BigDecimal_divide(Real **c, Real **res, Real **div, VALUE self, VALUE r)
if(!b) return DoSomeOne(self,r,'/');
SAVE(b);
*div = b;
- mx =(a->MaxPrec + b->MaxPrec + 1) * VpBaseFig();
+ 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"));
VpDivd(*c, *res, a, b);
@@ -1023,8 +1025,8 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
return (VALUE)0;
}
- 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"));
@@ -1036,6 +1038,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;