diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | numeric.c | 7 | ||||
-rw-r--r-- | test/ruby/test_fixnum.rb | 1 |
3 files changed, 12 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Sat Mar 19 21:53:35 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * numeric.c (fix_cmp): invert the result as the comarison is + inverted. + Sat Mar 19 18:32:00 2016 Kenta Murata <mrkn@mrkn.jp> * numeric.c (int_to_f): raise NotImplementedError when a receiver @@ -3425,7 +3425,12 @@ fix_cmp(VALUE x, VALUE y) return INT2FIX(-1); } else if (RB_TYPE_P(y, T_BIGNUM)) { - return rb_big_cmp(y, x); + VALUE cmp = rb_big_cmp(y, x); + switch (cmp) { + case INT2FIX(+1): return INT2FIX(-1); + case INT2FIX(-1): return INT2FIX(+1); + } + return cmp; } else if (RB_TYPE_P(y, T_FLOAT)) { return rb_integer_float_cmp(x, y); diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb index 024f905a43..3a1c2fa8bc 100644 --- a/test/ruby/test_fixnum.rb +++ b/test/ruby/test_fixnum.rb @@ -214,6 +214,7 @@ class TestFixnum < Test::Unit::TestCase assert_equal(0, 1 <=> 1) assert_equal(-1, 1 <=> 4294967296) + assert_equal(-1, 1 <=> 1 << 100) assert_equal(0, 1 <=> 1.0) assert_nil(1 <=> nil) |