diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-21 07:14:42 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-21 07:14:42 +0000 |
commit | f1a81f92cabff73ea06dd2bc8c8efbbc47d924fc (patch) | |
tree | 8eaf74b2c6525b989f53b8f34513a0faf5d3a077 /ext | |
parent | 5c71aadbed1ce4fcfe337911c5bcc5c4740b6b89 (diff) | |
download | ruby-f1a81f92cabff73ea06dd2bc8c8efbbc47d924fc.tar.gz |
* ext/bigdecimal/bigdecimal.c (VpMidRound): Round method bug
pointed by Ryan Platte fixed(Patch to the patch from "NATORI
Shin"). [ruby-talk:273360]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index c9e7ceb2e4..d2a351e984 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -4318,7 +4318,6 @@ Exit: /* * - * f = 0: Round off/Truncate, 1: round up, 2:ceil, 3: floor, 4: Banker's rounding * nf: digit position for operation. * */ @@ -4339,15 +4338,22 @@ VpMidRound(Real *y, int f, int nf) nf += y->exponent*((int)BASE_FIG); exptoadd=0; if (nf < 0) { + /* rounding position too left(large). */ + if((f!=VP_ROUND_CEIL) && (f!=VP_ROUND_FLOOR)) { + VpSetZero(y,VpGetSign(y)); /* truncate everything */ + return 0; + } exptoadd = -nf; nf = 0; } + /* ix: x->fraq[ix] contains round position */ ix = nf/(int)BASE_FIG; - if(((U_LONG)ix)>=y->Prec) return 0; /* Unable to round */ + if(((U_LONG)ix)>=y->Prec) return 0; /* rounding position too right(small). */ ioffset = nf - ix*((int)BASE_FIG); v = y->frac[ix]; + /* drop digits after pointed digit */ n = BASE_FIG - ioffset - 1; for(shifter=1,i=0;i<n;++i) shifter *= 10; |