summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2023-08-29 21:06:04 +0900
committernagachika <nagachika@ruby-lang.org>2023-08-29 21:06:04 +0900
commit5d568e18980b2fdec4701b52f2d89833fa20c0a8 (patch)
tree94fa09f70b4632ed8962fdef40a4dc6075f05d89
parente777064e4b064fd77aca65c123f1919433f6732d (diff)
merge revision(s) a28c5151f567cada0d2f5c0c3ec4df7f97b80784: [Backport #19855]
Fix Array#bsearch when block returns a non-integer numeric value --- array.c | 4 ++-- test/ruby/test_array.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-)
-rw-r--r--array.c4
-rw-r--r--test/ruby/test_array.rb4
-rw-r--r--version.h2
3 files changed, 7 insertions, 3 deletions
diff --git a/array.c b/array.c
index 654c79a44d..b76e9a64a3 100644
--- a/array.c
+++ b/array.c
@@ -3736,8 +3736,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
diff --git a/version.h b/version.h
index 8235f15c3e..08e6921662 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 2
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 113
+#define RUBY_PATCHLEVEL 114
#include "ruby/version.h"
#include "ruby/internal/abi.h"