summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog5
-rw-r--r--ext/bigdecimal/bigdecimal.c5
2 files changed, 8 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 600803c29e5..a8fa0cd3703 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Feb 9 23:26:07 2010 Yusuke Endoh <mame@tsg.ne.jp>
+
+ * ext/bigdecimal/bigdecimal.c (BigDecimal_DoDivmod): fix precision.
+ [ruby-core:17472][ruby-dev:35372][ruby-dev:40105][ruby-dev:40358]
+
Tue Feb 9 22:23:27 2010 Yusuke Endoh <mame@tsg.ne.jp>
* io.c (READ_CHECK): do not select fd before reading, that had made
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;