ruby-changes:51115
From: nobu <ko1@a...>
Date: Wed, 2 May 2018 22:37:23 +0900 (JST)
Subject: [ruby-changes:51115] nobu:r63322 (trunk): object.c: fix exponent with underscore
nobu 2018-05-02 22:37:18 +0900 (Wed, 02 May 2018) New Revision: 63322 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63322 Log: object.c: fix exponent with underscore * object.c (rb_cstr_to_dbl_raise): do not ignore exponent part when the input string longer than internal buffer contains underscore(s). [ruby-core:86836] [Bug #14731] Modified files: trunk/object.c trunk/test/ruby/test_float.rb Index: object.c =================================================================== --- object.c (revision 63321) +++ object.c (revision 63322) @@ -3270,7 +3270,8 @@ rb_cstr_to_dbl_raise(const char *p, int https://github.com/ruby/ruby/blob/trunk/object.c#L3270 if (*end) { char buf[DBL_DIG * 4 + 10]; char *n = buf; - char *e = buf + sizeof(buf) - 1; + char *const init_e = buf + DBL_DIG * 4; + char *e = init_e; char prev = 0; while (p < end && n < e) prev = *n++ = *p++; @@ -3283,6 +3284,9 @@ rb_cstr_to_dbl_raise(const char *p, int https://github.com/ruby/ruby/blob/trunk/object.c#L3284 } } prev = *p++; + if (e == init_e && (*p == 'e' || *p == 'E')) { + e = buf + sizeof(buf) - 1; + } if (n < e) *n++ = prev; } *n = '\0'; Index: test/ruby/test_float.rb =================================================================== --- test/ruby/test_float.rb (revision 63321) +++ test/ruby/test_float.rb (revision 63322) @@ -163,6 +163,8 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L163 assert_equal(-31.0*2**-1027, Float("-0x1f"+("0"*268)+".0p-2099")) assert_equal(-31.0*2**-1027, Float("-0x1f"+("0"*600)+".0p-3427")) end + + assert_equal(1.0e10, Float("1.0_"+"00000"*Float::DIG+"e10")) end def test_divmod -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/