From: Matthew Kerwin Date: 2012-06-14T14:24:13+09:00 Subject: Re: sqrt of rational numbers Dan Connelly wrote in post #1064519: > I was a bit surprised when I ran the following > > ... > > Now it works: > On 14 June 2012 14:33, Adam Ms. wrote: > No. You broke it. Read the Rational() docs. I'm only butting in here because I'm genuinely interested; how precisely is it broken? I read through http://www.ruby-doc.org/core-1.9.3/Rational.html and I can't see anything in Dan's patched Math#sqrt() that defies anything in the Rational() docs. Unless I'm not reading the right docs? Further from what I can see about how Rational reduces floating point numbers to ratios of integers, checking that the parts of the rational are perfect squares isn't necessary as the rationalised form has the same precision as a floating point number. However in terms of pretty, Math.sqrt(Rational(16,9)) # => (4/3) is nice, but Math.sqrt(Rational(17,9)) # => (1547401413261741/1125899906842624) is much uglier (to me) than 1.3743685418725535 --   Matthew Kerwin, B.Sc (CompSci) (Hons)   http://matthew.kerwin.net.au/   ABN: 59-013-727-651   "You'll never find a programming language that frees   you from the burden of clarifying your ideas." - xkcd