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

ruby-changes:21149

From: marcandre <ko1@a...>
Date: Tue, 6 Sep 2011 06:45:25 +0900 (JST)
Subject: [ruby-changes:21149] marcandRe: r33198 (trunk): * numeric.c (flo_round): Fix criteria for 32 bits platform

marcandre	2011-09-06 06:44:42 +0900 (Tue, 06 Sep 2011)

  New Revision: 33198

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33198

  Log:
    * numeric.c (flo_round): Fix criteria for 32 bits platform
      part 2 of [bug #5276]

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33197)
+++ ChangeLog	(revision 33198)
@@ -1,3 +1,8 @@
+Tue Sep  6 06:44:25 2011  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* numeric.c (flo_round): Fix criteria for 32 bits platform
+	  part 2 of [bug #5276]
+
 Tue Sep  6 05:37:11 2011  Masatoshi SEKI  <m_seki@m...>
 
 	* test/rinda/test_rinda.rb (test_core_03_notify): Fixed test failures
Index: numeric.c
===================================================================
--- numeric.c	(revision 33197)
+++ numeric.c	(revision 33198)
@@ -1560,16 +1560,16 @@
 	10 ** ((binexp-1)/log_2(10)) <= |number| < 10 ** (binexp/log_2(10))
 	If binexp >= 0, and since log_2(10) = 3.322259:
 	   10 ** (binexp/4 - 1) < |number| < 10 ** (binexp/3)
-	   binexp/4 <= exp <= binexp/3
+	   floor(binexp/4) <= exp <= ceil(binexp/3)
 	If binexp <= 0, swap the /4 and the /3
-	So if ndigits + binexp/(4 or 3) >= float_dig, the result is number
-	If ndigits + binexp/(3 or 4) < 0 the result is 0
+	So if ndigits + floor(binexp/(4 or 3)) >= float_dig, the result is number
+	If ndigits + ceil(binexp/(3 or 4)) < 0 the result is 0
 */
     if (isinf(number) || isnan(number) ||
-	(((long)ndigits - float_dig) * (3 + (binexp > 0)) + binexp >= 0)) {
+	(ndigits >= float_dig - (binexp > 0 ? binexp / 4 : binexp / 3 - 1))) {
 	return num;
     }
-    if ((long)ndigits * (4 - (binexp > 0)) + binexp < 0) {
+    if (ndigits < - (binexp > 0 ? binexp / 3 + 1 : binexp / 4)) {
 	return DBL2NUM(0);
     }
     f = pow(10, ndigits);

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

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