Subject: | Character dash '-' is not a valid digit |
When you define a specific digit set, no matter how many, if you use '-'
as a character... it will produce error using from base
Here is a quick sample :
---------------
my $calcX = new Math::BaseCalc(digits => [ '0', '-' ]);
for my $source (0..10) {
my $in_base_X = $calcX->to_base( $source );
my $in_base_10 = $calcX->from_base( $in_base_X );
print "source : $source ; from source to base X : ", $in_base_X, " ;
from base X to base 10 : ", $in_base_10, "\n";
}
---------------
Output is :
source : 0 ; from source to base X : 0 ; from base X to base 10 : 0
source : 1 ; from source to base X : - ; from base X to base 10 : 0
source : 2 ; from source to base X : -0 ; from base X to base 10 : 0
source : 3 ; from source to base X : -- ; from base X to base 10 : 0
source : 4 ; from source to base X : -00 ; from base X to base 10 : 0
source : 5 ; from source to base X : -0- ; from base X to base 10 : -1
source : 6 ; from source to base X : --0 ; from base X to base 10 : 0
source : 7 ; from source to base X : --- ; from base X to base 10 : 0
source : 8 ; from source to base X : -000 ; from base X to base 10 : 0
source : 9 ; from source to base X : -00- ; from base X to base 10 : -1
source : 10 ; from source to base X : -0-0 ; from base X to base 10 : -2
we expect to find the same number as source in the convertion process
from_base.
If you use any other chars than '-', you will not have this problem.