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

ruby-changes:17516

From: naruse <ko1@a...>
Date: Mon, 18 Oct 2010 10:02:07 +0900 (JST)
Subject: [ruby-changes:17516] Ruby:r29521 (trunk): * sprintf.c (BSD_vfprintf): wrong padding arround prefix and

naruse	2010-10-18 09:59:31 +0900 (Mon, 18 Oct 2010)

  New Revision: 29521

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

  Log:
    * sprintf.c (BSD_vfprintf): wrong padding arround prefix and
      floating point with %a. [ruby-dev:42403] Bug #3956

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29520)
+++ ChangeLog	(revision 29521)
@@ -1,3 +1,8 @@
+Mon Oct 18 09:57:28 2010  NARUSE, Yui  <naruse@r...>
+
+	* sprintf.c (BSD_vfprintf): wrong padding arround prefix and
+	  floating point with %a. [ruby-dev:42403] Bug #3956
+
 Sun Oct 17 22:36:33 2010  Tadayoshi Funaba  <tadf@d...>
 
 	* lib/date/delta.rb: added an rdoc tag.
Index: vsnprintf.c
===================================================================
--- vsnprintf.c	(revision 29520)
+++ vsnprintf.c	(revision 29521)
@@ -829,6 +829,9 @@
 				--expt;
 				expsize = exponent(expstr, expt, ch + 'p' - 'a');
 				size = expsize + ndig;
+				size += 2; /* 0x */
+				if (ndig > 1)
+					++size; /* floating point */
 			}
 			else if (ch <= 'e') {	/* 'e' or 'E' fmt */
 				--expt;
Index: test/ruby/test_sprintf.rb
===================================================================
--- test/ruby/test_sprintf.rb	(revision 29520)
+++ test/ruby/test_sprintf.rb	(revision 29521)
@@ -204,6 +204,13 @@
     assert_equal("Inf", sprintf("%E", Float::INFINITY))
     assert_equal("NaN", sprintf("%e", Float::NAN))
     assert_equal("NaN", sprintf("%E", Float::NAN))
+
+    assert_equal("   -0x1p+0", sprintf("%10a", -1))
+    assert_equal(" -0x1.8p+0", sprintf("%10a", -1.5))
+    assert_equal(" -0x1.4p+0", sprintf("%10a", -1.25))
+    assert_equal(" -0x1.2p+0", sprintf("%10a", -1.125))
+    assert_equal(" -0x1.1p+0", sprintf("%10a", -1.0625))
+    assert_equal("-0x1.05p+0", sprintf("%10a", -1.03125))
   end
 
   BSIZ = 120

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

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