ruby-changes:54582
From: nobu <ko1@a...>
Date: Sat, 12 Jan 2019 18:36:58 +0900 (JST)
Subject: [ruby-changes:54582] nobu:r66797 (trunk): No FloatDomainError at non-finitive number if exception: false
nobu 2019-01-12 18:36:52 +0900 (Sat, 12 Jan 2019) New Revision: 66797 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66797 Log: No FloatDomainError at non-finitive number if exception: false [ruby-core:91021] [Bug #15525] Modified files: trunk/object.c trunk/test/ruby/test_integer.rb Index: object.c =================================================================== --- object.c (revision 66796) +++ object.c (revision 66797) @@ -3159,6 +3159,7 @@ rb_convert_to_integer(VALUE val, int bas https://github.com/ruby/ruby/blob/trunk/object.c#L3159 double f; if (base != 0) goto arg_error; f = RFLOAT_VALUE(val); + if (!raise_exception && !isfinite(f)) return Qnil; if (FIXABLE(f)) return LONG2FIX((long)f); return rb_dbl2big(f); } Index: test/ruby/test_integer.rb =================================================================== --- test/ruby/test_integer.rb (revision 66796) +++ test/ruby/test_integer.rb (revision 66797) @@ -175,6 +175,15 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L175 def o.to_int; raise; end assert_equal(nil, Integer(o, exception: false)) } + assert_nothing_raised(FloatDomainError) { + assert_equal(nil, Integer(Float::INFINITY, exception: false)) + } + assert_nothing_raised(FloatDomainError) { + assert_equal(nil, Integer(-Float::INFINITY, exception: false)) + } + assert_nothing_raised(FloatDomainError) { + assert_equal(nil, Integer(Float::NAN, exception: false)) + } assert_raise(ArgumentError) { Integer("1z", exception: true) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/