Subject: | Large integers break |
I like this module. It's a lot cleaner and clearer than Math::BaseCnv.
However, I *think* Math::BaseCnv handles larger numbers properly,
whereas Math::Int2Base does not.
On my 64bit server using perl5.12.2, both modules output identical data
(when converting base 10 to base 62) from 1 to 100000000000000071. But
after that the output does not match. I tested with this loop:
use Math::BaseCnv;
use Math::Int2Base qw/ int2base base2int/;
for (my $i = $ARGV[0]; $i < $i + 1; $i++) {
my $bc1 = cnv($i, 10, 62);
my $ib1 = int2base($i, 62);
my $bc2 = cnv($bc1, 62, 10);
my $ib2 = base2int($ib1, 62);
say ("$bc1 : $ib1");
say ("$bc2 : $ib2");
last unless (($bc1 eq $ib1) && ($bc2 == $ib2));
}
Changing the following:
sub int2base {
my( $ret, $num, $base, $minlen ) = ( '', @_ );
$num ||= 0;
to:
sub int2base {
my( $ret, $num, $base, $minlen ) = ( '', @_ );
$num ||= 0;
$num = Math::BigInt->new($num);
seems to fix the problem converting from an integer. But I could not
figure out what to do to fix it going back the other way.
Just thought I'd point that out. Thanks for writing this!