summaryrefslogtreecommitdiffstats
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-21 07:14:42 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-21 07:14:42 +0000
commitf7bf83f3596eae0584dd0677e1c3814739da77a7 (patch)
tree8eaf74b2c6525b989f53b8f34513a0faf5d3a077 /ext/bigdecimal
parent9021fe53096dcbe2616d773a704c87c1cc2d2156 (diff)
downloadruby-f7bf83f3596eae0584dd0677e1c3814739da77a7.tar.gz
ruby-f7bf83f3596eae0584dd0677e1c3814739da77a7.tar.xz
ruby-f7bf83f3596eae0584dd0677e1c3814739da77a7.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@14414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index c9e7ceb2e..d2a351e98 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;