Skip to content

Commit

Permalink
merge revision(s) a28c515: [Backport #19855]
Browse files Browse the repository at this point in the history
	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(-)
  • Loading branch information
nagachika committed Aug 29, 2023
1 parent e777064 commit 5d568e1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions array.c
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions test/ruby/test_array.rb
Expand Up @@ -3336,6 +3336,8 @@ def test_bsearch_in_find_any_mode
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

Expand Down Expand Up @@ -3371,6 +3373,8 @@ def test_bsearch_index_in_find_any_mode
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

Expand Down
2 changes: 1 addition & 1 deletion version.h
Expand Up @@ -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"
Expand Down

0 comments on commit 5d568e1

Please sign in to comment.