Forum: Ruby-core [ruby-trunk - Bug #7728][Open] Range#bsearch on other Numerics?

Posted by marcandre (Marc-Andre Lafortune) (Guest)
on 2013-01-22 19:12
(Received via mailing list)
Issue #7728 has been reported by marcandre (Marc-Andre Lafortune).

----------------------------------------
Bug #7728: Range#bsearch on other Numerics?
https://bugs.ruby-lang.org/issues/7728

Author: marcandre (Marc-Andre Lafortune)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: 2.0.0
ruby -v: r38825


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 altogether

* BigDecimal
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).
Posted by marcandre (Marc-Andre Lafortune) (Guest)
on 2013-01-30 06:48
(Received via mailing list)
Issue #7728 has been updated by marcandre (Marc-Andre Lafortune).

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

Resolved with r38985.
----------------------------------------
Bug #7728: Range#bsearch on other Numerics?
https://bugs.ruby-lang.org/issues/7728#change-35716

Author: marcandre (Marc-Andre Lafortune)
Status: Closed
Priority: Normal
Assignee: marcandre (Marc-Andre Lafortune)
Category: core
Target version: 2.0.0
ruby -v: r38825


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 altogether

* BigDecimal
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).
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.