summaryrefslogtreecommitdiffstats
path: root/ext/bigdecimal
diff options
context:
space:
mode:
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;