From: Shigeo Kobayashi Date: 2007-10-09T22:16:15+09:00 Subject: Re: Bug in BigDecimal#round ? ------=_NextPart_000_00BB_01C80AB7.DE386570 Content-Type: text/plain; format=flowed; charset="ISO-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit Subject: Re: Bug in BigDecimal#round ? I attached the fix as a patch file. Could anyone(perhaps Matz ?) apply the patch ? With a change log like: Round method bug pointed by Ryan Platte fixed(Patch of the patch from "NATORI Shin"). Thank you in advance. Shigeo Kobayashi. ------=_NextPart_000_00BB_01C80AB7.DE386570 Content-Type: application/octet-stream; name="bigdecimal_round.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="bigdecimal_round.patch" --- bigdecimal.c.old 2007-10-02 20:21:52.421875000 +0900=0A= +++ bigdecimal.c 2007-10-04 20:22:07.234375000 +0900=0A= @@ -4319,7 +4319,6 @@=0A= =0A= /*=0A= *=0A= - * f =3D 0: Round off/Truncate, 1: round up, 2:ceil, 3: floor, 4: = Banker's rounding=0A= * nf: digit position for operation.=0A= *=0A= */=0A= @@ -4340,15 +4339,22 @@=0A= nf +=3D y->exponent*((int)BASE_FIG);=0A= exptoadd=3D0;=0A= if (nf < 0) {=0A= + /* rounding position too left(large). */=0A= + if((f!=3DVP_ROUND_CEIL) && (f!=3DVP_ROUND_FLOOR)) {=0A= + VpSetZero(y,VpGetSign(y)); /* truncate everything */=0A= + return 0;=0A= + }=0A= exptoadd =3D -nf;=0A= nf =3D 0;=0A= }=0A= +=0A= /* ix: x->fraq[ix] contains round position */=0A= ix =3D nf/(int)BASE_FIG;=0A= - if(((U_LONG)ix)>=3Dy->Prec) return 0; /* Unable to round */=0A= + if(((U_LONG)ix)>=3Dy->Prec) return 0; /* rounding position too = right(small). */=0A= ioffset =3D nf - ix*((int)BASE_FIG);=0A= =0A= v =3D y->frac[ix];=0A= +=0A= /* drop digits after pointed digit */=0A= n =3D BASE_FIG - ioffset - 1;=0A= for(shifter=3D1,i=3D0;i