Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit d48d4a89379f36b1ac2663350da662b7ac94f9d6 1 parent ede8b6d
@colomon colomon authored
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/NieczaActions.pm6
View
6 src/NieczaActions.pm6
@@ -129,6 +129,7 @@ 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;
@@ -136,7 +137,10 @@ sub from_base($str, $base) {
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
}
Please sign in to comment.
Something went wrong with that request. Please try again.