summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--insns.def15
-rw-r--r--test/ruby/test_fixnum.rb6
3 files changed, 15 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 9eb3a87..e697aa4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Feb 16 04:42:13 2016 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* tool/rbinstall.rb (without_destdir): compare with the destdir
diff --git a/insns.def b/insns.def
index 506bbe2..f9514d4 100644
--- a/insns.def
+++ b/insns.def
@@ -1332,12 +1332,7 @@ opt_plus
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
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)) {
diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb
index b5b6425..7e89caf 100644
--- a/test/ruby/test_fixnum.rb
+++ b/test/ruby/test_fixnum.rb
@@ -37,10 +37,14 @@ class TestFixnum < Test::Unit::TestCase
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
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