Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9b66e03176a3
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f8daad8183d7
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jul 29, 2015

  1. Copy the full SHA
    1b954d8 View commit details
  2. Merge pull request #3476 from kachick/range-bsearch

    Fix Range#bsearch for matching end value in find-minimum mode
    jc00ke committed Jul 29, 2015
    Copy the full SHA
    f8daad8 View commit details
Showing with 22 additions and 23 deletions.
  1. +22 −22 kernel/common/range.rb
  2. +0 −1 spec/tags/ruby/core/range/bsearch_tags.txt
44 changes: 22 additions & 22 deletions kernel/common/range.rb
Original file line number Diff line number Diff line change
@@ -51,47 +51,47 @@ def bsearch

last_true = nil

if max < 0 and min < 0
value = min + (max - min) / 2
elsif min < -max
value = -((-1 - min - max) / 2 + 1)
else
value = (min + max) / 2
end

while min < max
x = yield value
seeker = Proc.new do |current|
x = yield current

return value if x == 0
return current if x == 0

case x
when Numeric
if x > 0
min = value + 1
min = current + 1
else
max = value
max = current
end
when true
last_true = value
max = value
last_true = current
max = current
when false, nil
min = value + 1
min = current + 1
else
raise TypeError, "Range#bsearch block must return Numeric or boolean"
end
end

while min < max
if max < 0 and min < 0
value = min + (max - min) / 2
mid = min + (max - min) / 2
elsif min < -max
value = -((-1 - min - max) / 2 + 1)
mid = -((-1 - min - max) / 2 + 1)
else
value = (min + max) / 2
end
mid = (min + max) / 2
end

seeker.call mid
end

if min == max
seeker.call min
end

if min < max
return @begin if value == start
return @begin.kind_of?(Float) ? value.to_f : value
return @begin if mid == start
return @begin.kind_of?(Float) ? mid.to_f : mid
end

if last_true
1 change: 0 additions & 1 deletion spec/tags/ruby/core/range/bsearch_tags.txt

This file was deleted.