Subject: | from_base truncation of large integers |
use v5.10;
use bigint;
use Math::BaseCalc;
my $bignum =
85863250553302448437153211102345904505502971929758795587130289554944;
my $base89 = [0..9, 'A'..'Z', 'a'..'z', split(//,
'#$%&()*+,-/:;<=>?@[]^_`{|}~')]; # no !, ., ', ", or \
my $calc89 = Math::BaseCalc->new(digits => $base89);
my $hash = $calc89->to_base($bignum);
my $newnum = $calc89->from_base($hash);
say "BaseCalc via Base89";
say "===================";
say $bignum;
say $hash;
say $newnum;
say $newnum + 0;
say;
my $calc64 = Math::BaseCalc->new(digits => '64');
$hash = $calc64->to_base($bignum);
$newnum = $calc64->from_base($hash);
say "BaseCalc via Base64";
say "===================";
say $bignum;
say $hash;
say $newnum;
say $newnum + 0;
# BaseCalc via Base89
# ===================
# 85863250553302448437153211102345904505502971929758795587130289554944
# jCT3jUmD]hEtieNUC:y+`0gn$XmrbzR4U9x
# 8.58632505533025e+67
# 85863250553302500000000000000000000000000000000000000000000000000000
#
# BaseCalc via Base64
# ===================
# 85863250553302448437153211102345904505502971929758795587130289554944
# MvUgAAACIAAQAAADz/8/////////////8AgAYA
# 8.58632505533024e+67
# 85863250553302400000000000000000000000000000000000000000000000000000