## Bug #7728

### Range#bsearch on other Numerics?

**Description**

Range#bsearch attempts to do something on generic Numeric classes.

I feel it is both useless and buggy:

(Rational(-1,2)..Rational(9,4)).bsearch{|x| true} # => yields with 7/8 and 33/16 (Rational(-1,2)..Rational(9,4)).bsearch{|x| false} # => loops forever (BigDecimal('0.5')..BigDecimal('2.25'))... # => same

I feel the current implementation (aside from the bugs) only makes sense on Integers.

Possible approaches:

Rational

1) convert to float, or

2) bsearch accepts a "max iterations" parameter (which would be required for Rational), or

3) forbid altogetherBigDecimal

1) convert to float, or

2) look at the space of decimal numbers in the range without a higher precision than begin or end.

Given the timeframe though, I recommend we raise a TypeError for both in 2.0.0 (or a NotImplemented if we decide what should be done).

### Associated revisions

range.c: Restrict bsearch to integers [#7728]

test/ruby/test_range.rb: Test for above

range.c: Restrict bsearch to integers [#7728]

test/ruby/test_range.rb: Test for above

range.c: Restrict bsearch to integers [#7728]

test/ruby/test_range.rb: Test for above

range.c: Restrict bsearch to integers [#7728]

test/ruby/test_range.rb: Test for above

range.c: Restrict bsearch to integers [#7728]

test/ruby/test_range.rb: Test for above

range.c: Restrict bsearch to integers [#7728]

test/ruby/test_range.rb: Test for above

### History

#### Updated by marcandre (Marc-Andre Lafortune) about 6 years ago

**Status**changed from*Open*to*Closed***Assignee**set to*marcandre (Marc-Andre Lafortune)*

Resolved with r38985.

range.c: Restrict bsearch to integers [#7728]

test/ruby/test_range.rb: Test for above

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e