* 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
This commit is contained in:
matz 2007-12-21 07:14:42 +00:00
Родитель 5c71aadbed
Коммит f1a81f92ca
2 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Fri Dec 21 16:10:30 2007 Shigeo Kobayashi <shigeo@tinyforest.jp>
* ext/bigdecimal/bigdecimal.c (VpMidRound): Round method bug
pointed by Ryan Platte fixed(Patch to the patch from "NATORI
Shin"). [ruby-talk:273360]
Fri Dec 21 16:06:13 2007 Tanaka Akira <akr@fsij.org>
* re.c (append_utf8): use rb_utf8_encoding() instead of

Просмотреть файл

@ -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;