bigint vs. bignum

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello, I'm new to Perl

I have a small program, which uses only (big) integers, but works
differently with "use bigint" and "use bignum". Can you please explain

sub Next($)
  my $var = shift;
  my $tst = $var % 2;
  return ($tst == 0) ? $var / 2 : $var * 3 + 1;

my $n = 2 ** 1000 - 1;
my $counter = 0;

while (1)
  $n = Next($n);
  if ($n == 1)
    print("counter = ", $counter, "\n");

Thank you in advance

Re: bigint vs. bignum

Quoted text here. Click to load it

use bignum turns on upgrading.

When the division by 2 happens, the BigInt upgrades to BigFloat.  It
doesn't look to see if the division results in an integer before
upgrading--it just does it.


-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Site Timeline