in reply to Misunderstanding with Math::BigInt

because your code is equivalent to
my ($in_out) = @_; my ($out,$diver,$grade) = split(/,/, $in_out, 3); my $float = ($out)**(1/$grade)*$diver; my $in = Math::BigInt->new($float);
so you are making the calculation with floats and then converting the result to a bigint.

You have to convert first the numbers to bigints and then make the math!!!

Replies are listed 'Best First'.
Re^2: Misunderstanding with Math::BigInt
by Smoke (Initiate) on Jun 30, 2005 at 21:04 UTC
    what do you mean by 'convert first the numbers to bigints' ?
      As your code stands now, your variables are handled solely by perl's own internal representation, and aren't converted into bigints until the very last minute, after the exponentation and multiplication. At that point it is too late to preserve the extra tens of digits that you want, because they aren't there to be preserved.

      Convert your $out, $driver, and $grade variables to bigints before you do any exponentation and multiplying.

      By the way, don't you mean to use Math::BigFloat instead?

      John
      my ($in_out) = @_; my ($out,$diver,$grade) = split(/,/, $in_out, 3); $out = Math::BigInt->new($out); my $rgrade = Math::BigInt->new(1/$grade); $diver = Math::BigInt->new($diver); my $in = $out**$rgrade*$diver;