diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-03 09:12:41 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-03 09:12:41 +0000 |
commit | b1809bcff1c00a786fd8d5a98147cacf348c1b75 (patch) | |
tree | f4e69bdf809c3cc1deda20620f6d88d2890e745d | |
parent | 4fcb855ff382db0f0f8d849b5af48a652bd3494a (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
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 9 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 16 insertions, 4 deletions
@@ -1,3 +1,12 @@ +Tue Feb 9 23:48:25 2010 Yusuke Endoh <mame@tsg.ne.jp> + + * ext/bigdecimal/bigdecimal.c (BigDecimal_divide): fix precision too. + +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] + Thu Dec 10 01:12:55 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * parse.y (dyna_pop_gen): pop dvars. [ruby-dev:39861] 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; @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 422 +#define RUBY_PATCHLEVEL 423 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 |