Permalink
Browse files

Appropriate error message for out-of-range digits in a radix. This sh…

…ould probably be merged with the CORE.setting verison of the same function in the long run, but for now this makes things work.
  • Loading branch information...
1 parent ede8b6d commit d48d4a89379f36b1ac2663350da662b7ac94f9d6 @colomon colomon committed Mar 28, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/NieczaActions.pm6
View
@@ -129,14 +129,18 @@ method category:mod_internal ($ ) { }
method sign($ ) { }
+# This code should probably somehow be merged with the from_base in CORE.setting
sub from_base($str, $base) {
my $acc = 0;
my $punto = -1;
for $str.lc.comb -> $ch {
next if $ch eq '_';
if $ch eq '.' { $punto = 0; next; }
$punto++ if $punto >= 0;
- $acc = $acc * $base + ($ch ge 'a' ?? ord($ch) - 87 !! ord($ch) - 48);
+ my $digit = $ch ge 'a' ?? ord($ch) - 87 !! ord($ch) - 48;
+ die "Digit <$ch> too large for radix $base"
+ if $digit >= $base;
+ $acc = $acc * $base + $digit;
}
$punto >= 0 ?? $acc / ($base ** $punto) !! $acc
}

0 comments on commit d48d4a8

Please sign in to comment.