diff --git a/object.c b/object.c index 4a5b5d359a..a4594a2982 100644 --- a/object.c +++ b/object.c @@ -3270,7 +3270,8 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) 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 badcheck, int raise, int *error) } } prev = *p++; + if (e == init_e && (*p == 'e' || *p == 'E')) { + e = buf + sizeof(buf) - 1; + } if (n < e) *n++ = prev; } *n = '\0'; diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 24bed9269c..5686fd4617 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -163,6 +163,8 @@ class TestFloat < Test::Unit::TestCase 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