aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--numeric.c2
-rw-r--r--test/ruby/test_bignum.rb12
3 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d25205319c..4c9ee5462f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue May 19 13:10:08 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* lib/uri/rfc2396_parser.rb (initialize_pattern):
diff --git a/numeric.c b/numeric.c
index e2f330f3bc..0620442bae 100644
--- a/numeric.c
+++ b/numeric.c
@@ -666,7 +666,7 @@ num_positive_p(VALUE num)
}
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));
}
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index 2c6eda0d8e..012a5624d0 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -268,6 +268,18 @@ class TestBignum < Test::Unit::TestCase
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