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) 8 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 #1

Updated by nobu (Nobuyoshi Nakada) 8 months ago

  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) 8 months ago

  • Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE

ruby_3_2 5d568e18980b2fdec4701b52f2d89833fa20c0a8 merged revision(s) a28c5151f567cada0d2f5c0c3ec4df7f97b80784.

Updated by usa (Usaku NAKAMURA) 7 months ago

  • Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE to 3.0: REQUIRED, 3.1: DONE, 3.2: DONE

ruby_3_1 eb54ed809f61fb25a0de101a7a6a649e8d4a434c merged revision(s) a28c5151f567cada0d2f5c0c3ec4df7f97b80784.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0