From: Dave Burt Date: 2005-05-12T22:30:27+09:00 Subject: Re: Standard Library patches - rational, delegate "gabriele renzi" kindly suggested... > Dave Burt ha scritto: >> Hi, >> >> I have two small things I would like to see changed in the standard >> library: >> delegate.rb >> rational.rb > > if this is a fix you can point out the bug on the ruby issue tracker on > rubyforge, and attach the patch. Or you can post it on ruby-core. Does ruby-core deal with standard library as well as core? >> The second are some enhancements to Rational, mainly to make it more >> friendly with Floats and Strings, allowing rationals to be made like >> Rational("2/3"), Rational("1.2e-10"), Rational(0.5), as well as adding >> to_r methods to String and Float. > > This sounds more of an RCR, use RCRChive.net . You've suggested ruby-core and RCR; I thought that as it's not a language change, they're not the right avenues. You have to do an explicit "require" to get these libraries. Is it appropriate to submit an RCR for a standard library change? >> 1.6.to_r #=> Rational(3602879701896397, 2251799813685248) >> 1.6.to_r.approximate #=> Rational(8, 5) > > I wonder if this would'nt cause a problem for new users which could get > the false sense of security from float operations. > Also, have you thought of intehration with BigDecimal ? > And finaly.. I don't love the to_x methods (since there is so little room > for them), but in general I think your patch makes sense. By default, the conversion is exact - the Rational is an exact representation of the Float's value. You need to explicitly invoke an approximation method. Reciprocal integration with BigDecimal is a good suggestion, thank you for it. Thanks very much for the feedback, Gabriele. Dave.