in reply to Re: issues using bigrat
in thread issues using bigrat

You changed
$s += $k / ($n-$k);
to
$s += ($n + 1 - $i) / $i;

The "+ 1" has the same effect as the "1 *" the OP used in his fixed version. Just like him, your $n and $i are plain integers, not big ints.

Replies are listed 'Best First'.
Re^3: issues using bigrat
by perl-diddler (Chaplain) on May 11, 2008 at 21:47 UTC
    Yeah, you might think so, but if my code has the same problem, why does it not suffer the same problem calling numerator or denominator on "$s"?

    I mean the output is, I believe, what would expect if it was working correctly:

    n = 1, s = 1, num=1, den=1 n = 2, s = 5/2, num=5, den=2 n = 3, s = 13/3, num=13, den=3 n = 4, s = 77/12, num=77, den=12 n = 5, s = 87/10, num=87, den=10 nums=1, 5, 13, 77, 87 dens=1, 2, 3, 12, 10
    Hmmm...not sure but it may that the original example that "worked" didn't really produce the right output or wasn't doing the right computation.

      why does it not suffer the same problem calling numerator or denominator on "$s"?

      "Same problem"? His doesn't suffer from such a problem either. Both your results and his are BigRats

      Update: Bad test. And you've already answered yourself.