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

ruby-changes:44465

From: nobu <ko1@a...>
Date: Tue, 1 Nov 2016 21:35:37 +0900 (JST)
Subject: [ruby-changes:44465] nobu:r56538 (trunk): numeric.c: fix return value on big 0

nobu	2016-11-01 21:35:32 +0900 (Tue, 01 Nov 2016)

  New Revision: 56538

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

  Log:
    numeric.c: fix return value on big 0
    
    * numeric.c (num_zero_p): should return true if zero.
      rb_bigzero_p returns 1 or 0.

  Modified files:
    trunk/numeric.c
    trunk/test/-ext-/bignum/test_bigzero.rb
Index: test/-ext-/bignum/test_bigzero.rb
===================================================================
--- test/-ext-/bignum/test_bigzero.rb	(revision 56537)
+++ test/-ext-/bignum/test_bigzero.rb	(revision 56538)
@@ -10,5 +10,11 @@ class TestBignum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_bigzero.rb#L10
         assert_equal(0, Bug::Bignum.zero(i), "#{bug8204} Bignum.zero(#{i})")
       end
     end
+
+    def test_zero?
+      (0..10).each do |i|
+        assert_equal(true, Bug::Bignum.zero(i).zero?)
+      end
+    end
   end
 end
Index: numeric.c
===================================================================
--- numeric.c	(revision 56537)
+++ numeric.c	(revision 56538)
@@ -721,7 +721,10 @@ num_zero_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L721
 	}
     }
     else if (RB_TYPE_P(num, T_BIGNUM)) {
-	return rb_bigzero_p(num);
+	if (rb_bigzero_p(num)) {
+	    /* this should not happen usually */
+	    return Qtrue;
+	}
     }
     else if (rb_equal(num, INT2FIX(0))) {
 	return Qtrue;

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

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