ruby-changes:41765
From: naruse <ko1@a...>
Date: Tue, 16 Feb 2016 04:42:38 +0900 (JST)
Subject: [ruby-changes:41765] naruse:r53839 (trunk): * insns.def (opt_plus): simply use LONG2NUM() instead of wrongly
naruse 2016-02-16 04:42:59 +0900 (Tue, 16 Feb 2016) New Revision: 53839 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53839 Log: * insns.def (opt_plus): simply use LONG2NUM() instead of wrongly complex overflow case. * insns.def (opt_sub): ditto. Modified files: trunk/ChangeLog trunk/insns.def trunk/test/ruby/test_fixnum.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 53838) +++ ChangeLog (revision 53839) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Feb 16 04:42:13 2016 NARUSE, Yui <naruse@r...> + + * insns.def (opt_plus): simply use LONG2NUM() instead of wrongly + complex overflow case. + + * insns.def (opt_sub): ditto. + Tue Feb 16 02:49:41 2016 Nobuyoshi Nakada <nobu@r...> * tool/rbinstall.rb (without_destdir): compare with the destdir Index: insns.def =================================================================== --- insns.def (revision 53838) +++ insns.def (revision 53839) @@ -1332,12 +1332,7 @@ opt_plus https://github.com/ruby/ruby/blob/trunk/insns.def#L1332 a = FIX2LONG(recv); b = FIX2LONG(obj); c = a + b; - if (FIXABLE(c)) { - val = LONG2FIX(c); - } - else { - val = rb_big_plus(rb_int2big(a), rb_int2big(b)); - } + val = LONG2NUM(c); #endif } else if (FLONUM_2_P(recv, obj) && @@ -1387,13 +1382,7 @@ opt_minus https://github.com/ruby/ruby/blob/trunk/insns.def#L1382 a = FIX2LONG(recv); b = FIX2LONG(obj); c = a - b; - - if (FIXABLE(c)) { - val = LONG2FIX(c); - } - else { - val = rb_big_minus(rb_int2big(a), rb_int2big(b)); - } + val = LONG2NUM(c); } else if (FLONUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED_P(BOP_MINUS, FLOAT_REDEFINED_OP_FLAG)) { Index: test/ruby/test_fixnum.rb =================================================================== --- test/ruby/test_fixnum.rb (revision 53838) +++ test/ruby/test_fixnum.rb (revision 53839) @@ -37,10 +37,14 @@ class TestFixnum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fixnum.rb#L37 def test_plus assert_equal(0x40000000, 0x3fffffff+1) + assert_equal(0x7ffffffe, 0x3fffffff+0x3fffffff) assert_equal(0x4000000000000000, 0x3fffffffffffffff+1) + assert_equal(0x7ffffffffffffffe, 0x3fffffffffffffff+0x3fffffffffffffff) assert_equal(-0x40000001, (-0x40000000)+(-1)) assert_equal(-0x4000000000000001, (-0x4000000000000000)+(-1)) + assert_equal(-0x7ffffffe, (-0x3fffffff)+(-0x3fffffff)) assert_equal(-0x80000000, (-0x40000000)+(-0x40000000)) + assert_equal(-0x8000000000000000, (-0x4000000000000000)+(-0x4000000000000000)) end def test_sub @@ -49,6 +53,8 @@ class TestFixnum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fixnum.rb#L53 assert_equal(-0x40000001, (-0x40000000)-1) assert_equal(-0x4000000000000001, (-0x4000000000000000)-1) assert_equal(-0x80000000, (-0x40000000)-0x40000000) + assert_equal(0x7fffffffffffffff, 0x3fffffffffffffff-(-0x4000000000000000)) + assert_equal(-0x8000000000000000, -0x4000000000000000-0x4000000000000000) end def test_mult -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/