diff options
-rw-r--r-- | array.c | 4 | ||||
-rw-r--r-- | test/ruby/test_array.rb | 4 |
2 files changed, 6 insertions, 2 deletions
@@ -3522,8 +3522,8 @@ rb_ary_bsearch_index(VALUE ary) const VALUE zero = INT2FIX(0); switch (rb_cmpint(rb_funcallv(v, id_cmp, 1, &zero), v, zero)) { case 0: return INT2FIX(mid); - case 1: smaller = 1; break; - case -1: smaller = 0; + case 1: smaller = 0; break; + case -1: smaller = 1; } } else { diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index f58f8a2778..6c0db0832b 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -3336,6 +3336,8 @@ class TestArray < Test::Unit::TestCase assert_equal(nil, a.bsearch {|x| 1 * (2**100) }) assert_equal(nil, a.bsearch {|x| (-1) * (2**100) }) + assert_equal(4, a.bsearch {|x| (4 - x).to_r }) + assert_include([4, 7], a.bsearch {|x| (2**100).coerce((1 - x / 4) * (2**100)).first }) end @@ -3371,6 +3373,8 @@ class TestArray < Test::Unit::TestCase assert_equal(nil, a.bsearch_index {|x| 1 * (2**100) }) assert_equal(nil, a.bsearch_index {|x| (-1) * (2**100) }) + assert_equal(1, a.bsearch_index {|x| (4 - x).to_r }) + assert_include([1, 2], a.bsearch_index {|x| (2**100).coerce((1 - x / 4) * (2**100)).first }) end |