Project

General

Profile

Actions

Bug #19855

closed

Array#bsearch gets wrong result when its block returns a non-integer numeric value.

Added by kyanagi (Kouhei Yanagita) 9 months ago. Updated 7 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0dev (2023-08-29T04:52:18Z master c0e913ae88) [arm64-darwin22]
[ruby-core:114574]

Description

Array#bsearch gets wrong result when its block returns a non-integer numeric value.

% ruby -e 'p [0, 4, 7, 10, 12].bsearch { |x| (4 - x) }'
4
% ruby -e 'p [0, 4, 7, 10, 12].bsearch { |x| (4 - x).to_r }'
nil

fix: https://github.com/ruby/ruby/pull/8314

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0