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

ruby-changes:17718

From: naruse <ko1@a...>
Date: Tue, 9 Nov 2010 10:57:57 +0900 (JST)
Subject: [ruby-changes:17718] Ruby:r29729 (trunk): * util.c (ruby_strtod): this code uses FPU's rounding system.

naruse	2010-11-09 10:57:49 +0900 (Tue, 09 Nov 2010)

  New Revision: 29729

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

  Log:
    * util.c (ruby_strtod): this code uses FPU's rounding system.
      But x86's FPU calculates double precision floating-point
      numbers in 80bit precision, so it fails to round the value.
      So ensure the value is assigned a variable. [ruby-dev:42551]
      see also [ruby-math:00802]
      http://www.shudo.net/java-grandprix99/strictfp/

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_sprintf.rb
    trunk/util.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29728)
+++ ChangeLog	(revision 29729)
@@ -1,3 +1,12 @@
+Tue Nov  9 10:44:19 2010  NARUSE, Yui  <naruse@r...>
+
+	* util.c (ruby_strtod): this code uses FPU's rounding system.
+	  But x86's FPU calculates double precision floating-point
+	  numbers in 80bit precision, so it fails to round the value.
+	  So ensure the value is assigned a variable. [ruby-dev:42551]
+	  see also [ruby-math:00802]
+	  http://www.shudo.net/java-grandprix99/strictfp/
+
 Tue Nov  9 07:30:15 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* error.c (rb_syserr_new): new function to make SystemCallError
Index: util.c
===================================================================
--- util.c	(revision 29728)
+++ util.c	(revision 29729)
@@ -4014,10 +4014,13 @@
 	/* Round to the desired number of digits. */
 	if (SIGFIGS > ndigits && ndigits > 0) {
 		float redux = 1.0f;
+		volatile double d;
 		int offset = 4 * ndigits + DBL_MAX_EXP - 4 - DBL_MANT_DIG;
 		dexp_set(u, offset);
-		u.d += redux;
-		u.d -= redux;
+		d = u.d;
+		d += redux;
+		d -= redux;
+		u.d = d;
 		*decpt += dexp_get(u) - offset;
 	}
 
Index: test/ruby/test_sprintf.rb
===================================================================
--- test/ruby/test_sprintf.rb	(revision 29728)
+++ test/ruby/test_sprintf.rb	(revision 29729)
@@ -190,6 +190,8 @@
                  sprintf("%20.0f", 36893488147419107329.0))
     assert_equal(" Inf", sprintf("% 0e", 1.0/0.0), "moved from btest/knownbug")
     assert_equal("       -0.", sprintf("%#10.0f", -0.5), "[ruby-dev:42552]")
+    assert_equal("0x1.p+2",   sprintf('%.0a', Float('0x1.fp+1')),   "[ruby-dev:42551]")
+    assert_equal("-0x1.0p+2", sprintf('%.0a', Float('-0x1.ffp+1')), "[ruby-dev:42551]")
   end
 
   def test_float_hex

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

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