From: Charles Oliver Nutter Date: 2009-02-15T19:04:44+09:00 Subject: [ruby-core:22140] Re: Confused about some code in mathn.rb Charles Oliver Nutter wrote: > Charles Oliver Nutter wrote: >> In 1.8.6 and 1.8.7, these lines appear at line 202 in mathn.rb: >> >> loop do >> if (neard**other.denominator == self.denominator) >> dem = neaed >> break >> end >> end >> >> I'm confused about the purpose of this code. If the equality check >> fails, it will simply loop forever. If the equality check passes, it >> will end after a single loop. So what's the purpose of the loop? >> >> Perhaps it never happens in MRI but for a particular spec running >> under JRuby it ends up comparing 3.999999999999999 with 4.0. I'm >> looking into whether we can tweak the power computation in JRuby to >> produce the 4.0 result, but it's still rather confusing what the code >> above is intended to do. Anyone? > > More confusion in the same method...if I comment out the loop, it > continues on and blows up in trying to call num on self (a Rational). > But Rational does not define num, it defines numerator: > > at line 208: > nearn = self.numerator.to_f ** (1.0/other.denominator.to_f) > Rational(num,den) > > There is no definition of num or den as variables anywhere in the power2 > method. I'm not sure how this method is supposed to work at all... FWIW, this code seems to be the same on 1_8 branch. If I comment out the loop and replace Rational(num,den) with Rational(numerator,denominator) it seems to function, but obviously I'm still confused about why the loop is there at all. - Charlie