ruby-changes:38457
From: nobu <ko1@a...>
Date: Tue, 19 May 2015 13:10:47 +0900 (JST)
Subject: [ruby-changes:38457] nobu:r50538 (trunk): numeric.c: Bignum 0 is not positive
nobu 2015-05-19 13:10:12 +0900 (Tue, 19 May 2015) New Revision: 50538 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50538 Log: numeric.c: Bignum 0 is not positive * numeric.c (num_positive_p): should false on Bignum 0. http://twitter.com/rafaelfranca/status/600509783427391488 [ruby-core:69173] [Feature #11151] Modified files: trunk/ChangeLog trunk/numeric.c trunk/test/ruby/test_bignum.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 50537) +++ ChangeLog (revision 50538) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue May 19 13:10:08 2015 Nobuyoshi Nakada <nobu@r...> + + * numeric.c (num_positive_p): should false on Bignum 0. + http://twitter.com/rafaelfranca/status/600509783427391488 + [ruby-core:69173] [Feature #11151] + Tue May 19 11:22:28 2015 NARUSE, Yui <naruse@r...> * lib/uri/rfc2396_parser.rb (initialize_pattern): Index: numeric.c =================================================================== --- numeric.c (revision 50537) +++ numeric.c (revision 50538) @@ -666,7 +666,7 @@ num_positive_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L666 } else if (RB_TYPE_P(num, T_BIGNUM)) { if (method_basic_p(rb_cBignum)) - return BIGNUM_POSITIVE_P(num); + return BIGNUM_POSITIVE_P(num) && !rb_bigzero_p(num); } return RTEST(compare_with_zero(num, mid)); } Index: test/ruby/test_bignum.rb =================================================================== --- test/ruby/test_bignum.rb (revision 50537) +++ test/ruby/test_bignum.rb (revision 50538) @@ -268,6 +268,18 @@ class TestBignum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_bignum.rb#L268 assert_equal(2**180, (2**80) * o) end + def test_positive_p + assert_predicate(T_ONE, :positive?) + assert_not_predicate(T_MONE, :positive?) + assert_not_predicate(T_ZERO, :positive?) + end + + def test_negative_p + assert_not_predicate(T_ONE, :negative?) + assert_predicate(T_MONE, :negative?) + assert_not_predicate(T_ZERO, :negative?) + end + def test_mul_balance assert_equal(3**7000, (3**5000) * (3**2000)) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/