[前][次][番号順一覧][スレッド一覧]

ruby-changes:2923

From: ko1@a...
Date: 21 Dec 2007 16:14:55 +0900
Subject: [ruby-changes:2923] matz - Ruby:r14414 (trunk): * ext/bigdecimal/bigdecimal.c (VpMidRound): Round method bug

matz	2007-12-21 16:14:42 +0900 (Fri, 21 Dec 2007)

  New Revision: 14414

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c

  Log:
    * ext/bigdecimal/bigdecimal.c (VpMidRound): Round method bug
      pointed by Ryan Platte fixed(Patch to the patch from "NATORI
      Shin").  [ruby-talk:273360]

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14414&r2=14413
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/bigdecimal/bigdecimal.c?r1=14414&r2=14413

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14413)
+++ ChangeLog	(revision 14414)
@@ -1,3 +1,9 @@
+Fri Dec 21 16:10:30 2007  Shigeo Kobayashi  <shigeo@t...>
+
+	* 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@f...>
 
 	* re.c (append_utf8): use rb_utf8_encoding() instead of
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 14413)
+++ ext/bigdecimal/bigdecimal.c	(revision 14414)
@@ -4318,7 +4318,6 @@
 
 /*
  *
- * 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 @@
     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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]