ruby-changes:44655
From: usa <ko1@a...>
Date: Sat, 12 Nov 2016 07:37:58 +0900 (JST)
Subject: [ruby-changes:44655] usa:r56728 (ruby_2_2): merge revision(s) 53533: [Backport #12895]
usa 2016-11-12 07:37:54 +0900 (Sat, 12 Nov 2016) New Revision: 56728 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56728 Log: merge revision(s) 53533: [Backport #12895] * sprintf.c (rb_str_format): format exact number more exactly. Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/sprintf.c branches/ruby_2_2/test/ruby/test_sprintf.rb branches/ruby_2_2/version.h Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 56727) +++ ruby_2_2/ChangeLog (revision 56728) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Sat Nov 12 07:37:30 2016 Nobuyoshi Nakada <nobu@r...> + + * sprintf.c (rb_str_format): format exact number more exactly. + Sat Nov 12 07:34:03 2016 Kazuki Yamaguchi <k@r...> * ext/openssl/ossl.c (Init_openssl): register an ex_data index for Index: ruby_2_2/sprintf.c =================================================================== --- ruby_2_2/sprintf.c (revision 56727) +++ ruby_2_2/sprintf.c (revision 56728) @@ -1024,13 +1024,19 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/ruby_2_2/sprintf.c#L1024 int sign = (flags&FPLUS) ? 1 : 0, zero = 0; long len, done = 0; int prefix = 0; - if (!RB_TYPE_P(val, T_RATIONAL)) { + if (FIXNUM_P(val) || RB_TYPE_P(val, T_BIGNUM)) { + den = INT2FIX(1); + num = val; + } + else if (RB_TYPE_P(val, T_RATIONAL)) { + den = rb_rational_den(val); + num = rb_rational_num(val); + } + else { nextvalue = val; goto float_value; } if (!(flags&FPREC)) prec = default_float_precision; - den = rb_rational_den(val); - num = rb_rational_num(val); if (FIXNUM_P(num)) { if ((SIGNED_VALUE)num < 0) { long n = -FIX2LONG(num); Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 56727) +++ ruby_2_2/version.h (revision 56728) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.6" #define RUBY_RELEASE_DATE "2016-11-12" -#define RUBY_PATCHLEVEL 386 +#define RUBY_PATCHLEVEL 387 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 11 Index: ruby_2_2/test/ruby/test_sprintf.rb =================================================================== --- ruby_2_2/test/ruby/test_sprintf.rb (revision 56727) +++ ruby_2_2/test/ruby/test_sprintf.rb (revision 56728) @@ -148,6 +148,11 @@ class TestSprintf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_sprintf.rb#L148 assert_equal(" Inf", sprintf("% e", inf), '[ruby-dev:34002]') end + def test_bignum + assert_match(/\A10{120}\.0+\z/, sprintf("%f", 100**60)) + assert_match(/\A10{180}\.0+\z/, sprintf("%f", 1000**60)) + end + def test_rational assert_match(/\A0\.10+\z/, sprintf("%.60f", 0.1r)) assert_match(/\A0\.010+\z/, sprintf("%.60f", 0.01r)) Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r53533 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/