Hi
It seems that to_base has issues with large integers. I've tested by
converting 2^63-1 into base 36, but the second last digit ('e' below)
becomes a '0' instead of an 'e' as expected.
my $int = 9223372036854775807; # 2^63-1
my $int_base36 = '1y2p0ij32e8e7'; # 2^63-1 in base 36
my $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z']);
my $base36 = $calc36->to_base($int);
After this, I expect $base36 and $int_base36 to have the same value.
They don't.
from_base works fine for converting the other way.
Please see the attached test for a bit more elaborate roundtrip test case.
Best regards
Jacob
Subject: | large_int_base36.t |
use Test::More tests=>5;
use strict;
use warnings;
use_ok('Math::BaseCalc');
is($Math::BaseCalc::VERSION, '1.014', "Lastest version");
my $int = 9223372036854775807; # 2^63-1
my $int_base36 = '1y2p0ij32e8e7';
my $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z']);
my $base36 = $calc36->to_base($int);
is($base36,$int_base36, "to_base has done proper conversion of $int");
my $int2 = $calc36->from_base($base36);
is($int2,$int, "$int has roundtripped");
$int2 = $calc36->from_base($int_base36);
is($int2, $int, "from_base correct for $int_base36 ($int)");