ruby-changes:35140
From: nobu <ko1@a...>
Date: Tue, 19 Aug 2014 22:28:42 +0900 (JST)
Subject: [ruby-changes:35140] nobu:r47222 (trunk): sprintf.c: fix condition
nobu 2014-08-19 22:28:32 +0900 (Tue, 19 Aug 2014) New Revision: 47222 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47222 Log: sprintf.c: fix condition * sprintf.c (rb_str_format): fix condition to round. [ruby-core:64454] [Bug #10151] Modified files: trunk/ChangeLog trunk/sprintf.c trunk/test/ruby/test_sprintf.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 47221) +++ ChangeLog (revision 47222) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Aug 19 22:28:32 2014 Nobuyoshi Nakada <nobu@r...> + + * sprintf.c (rb_str_format): fix condition to round. + [ruby-core:64454] [Bug #10151] + Tue Aug 19 22:22:45 2014 Nobuyoshi Nakada <nobu@r...> * enc/trans/euckr-tbl.rb (EUCKR_TO_UCS_TBL): add missing euro and Index: sprintf.c =================================================================== --- sprintf.c (revision 47221) +++ sprintf.c (revision 47222) @@ -1045,7 +1045,7 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/sprintf.c#L1045 sign = -1; num = rb_funcallv(num, idUMinus, 0, 0); } - if (den != INT2FIX(1) && prec > 1) { + if (den != INT2FIX(1) || prec > 1) { const ID idDiv = rb_intern("div"); VALUE p10 = rb_int_positive_pow(10, prec); VALUE den_2 = rb_funcall(den, idDiv, 1, INT2FIX(2)); Index: test/ruby/test_sprintf.rb =================================================================== --- test/ruby/test_sprintf.rb (revision 47221) +++ test/ruby/test_sprintf.rb (revision 47222) @@ -151,6 +151,7 @@ class TestSprintf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_sprintf.rb#L151 def test_rational assert_match(/\A0\.10+\z/, sprintf("%.60f", 0.1r)) assert_match(/\A0\.3+\z/, sprintf("%.60f", 1/3r)) + assert_match(/\A1\.20+\z/, sprintf("%.60f", 1.2r)) end def test_hash -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/