rubyworks / radix

Base Conversions
http://rubyworks.github.com/radix
Other
54 stars 9 forks source link

Float#to_r is broken, unnecessary in ruby 1.9 #5

Closed simonratner closed 11 years ago

simonratner commented 12 years ago

Firstly, the patch to Float#to_r that this module applies is broken. https://github.com/rubyworks/radix/blob/master/lib/radix/rational.rb#L199

- d = (10 * f.size).to_i
+ d = (10 ** f.size).to_i

This results in some rather amusing bugs, such as Rational(0.71) == (71/20).

Secondly, ruby 1.9+ provides a native, and more correct, implementation of Float#to_r, so it should not be patched at all.

trans commented 11 years ago

Don't I feel stupid! ;-)

Thanks for catching this. It's been fixed and will be in the 2.1.0 release. Note I conditioned the use of the fixed core extension to RUBY_VERSION < '1.9'.

Please let me know if there's anything else I can do to improve Radix.