Permalink
Browse files

Loosen argument types on Int.expmod, add sub expmod.

  • Loading branch information...
1 parent 1760451 commit 83d732c2640436c3ee1e8c93ed51d99009b77d51 @colomon colomon committed Sep 22, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/CORE.setting
View
@@ -845,14 +845,17 @@ my class Int does Integral {
push @res, '-' if self < 0;
join '', @res.reverse;
}
- method expmod(Int $y is copy, Int $mod) {
+ method expmod($power, $mod) {
# Routine by TimToady; should probably be replaced with
# C# version at some point.
my $x = self;
+ my $y = $power.Int;
+ my $z = $mod.Int;
+
my $result = 1;
repeat while $y div= 2 {
- ($result *= $x) %= $mod if $y % 2;
- ($x *= $x) %= $mod;
+ ($result *= $x) %= $z if $y % 2;
+ ($x *= $x) %= $z;
}
$result;
}
@@ -3858,6 +3861,7 @@ sub hypot($a, $b) is pure {
my $r = $min / $max;
$max * sqrt(1 + $r * $r);
}
+sub expmod($exp, $base, $mod) { $exp.Int.expmod($base, $mod) }
sub pick($num, *@values) { @values.pick($num) }
sub roll($num, *@values) { @values.roll($num) }

0 comments on commit 83d732c

Please sign in to comment.