[前][次][番号順一覧][スレッド一覧]

ruby-changes:42120

From: nobu <ko1@a...>
Date: Sat, 19 Mar 2016 21:53:45 +0900 (JST)
Subject: [ruby-changes:42120] nobu:r54194 (trunk): fix r54193

nobu	2016-03-19 21:53:36 +0900 (Sat, 19 Mar 2016)

  New Revision: 54194

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54194

  Log:
    fix r54193
    
    * numeric.c (fix_cmp): invert the result as the comarison is
      inverted.

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
    trunk/test/ruby/test_fixnum.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54193)
+++ ChangeLog	(revision 54194)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Mar 19 21:53:35 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (fix_cmp): invert the result as the comarison is
+	  inverted.
+
 Sat Mar 19 18:32:00 2016  Kenta Murata  <mrkn@m...>
 
 	* numeric.c (int_to_f): raise NotImplementedError when a receiver
Index: test/ruby/test_fixnum.rb
===================================================================
--- test/ruby/test_fixnum.rb	(revision 54193)
+++ test/ruby/test_fixnum.rb	(revision 54194)
@@ -214,6 +214,7 @@ class TestFixnum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fixnum.rb#L214
 
     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)
 
Index: numeric.c
===================================================================
--- numeric.c	(revision 54193)
+++ numeric.c	(revision 54194)
@@ -3425,7 +3425,12 @@ fix_cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3425
 	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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]