Skip to content
Browse files

Borrow TimToady++'s implementation of expmod.

  • Loading branch information...
1 parent f226bf6 commit 17604511ff2843162fe1abe63c53db409dfc597c @colomon colomon committed Sep 21, 2012
Showing with 12 additions and 0 deletions.
  1. +11 −0 lib/CORE.setting
  2. +1 −0 t/spectest.data
View
11 lib/CORE.setting
@@ -845,6 +845,17 @@ my class Int does Integral {
push @res, '-' if self < 0;
join '', @res.reverse;
}
+ method expmod(Int $y is copy, Int $mod) {
+ # Routine by TimToady; should probably be replaced with
+ # C# version at some point.
+ my $x = self;
+ my $result = 1;
+ repeat while $y div= 2 {
+ ($result *= $x) %= $mod if $y % 2;
+ ($x *= $x) %= $mod;
+ }
+ $result;
+ }
}
my class Rat does Real {
method new($n,$d) { $n / $d }
View
1 t/spectest.data
@@ -513,6 +513,7 @@ S32-num/base.t
S32-num/complex.t
S32-num/cool-num.t
S32-num/exp.t
+S32-num/expmod.t
S32-num/fatrat.t
S32-num/int.t
S32-num/log.t

0 comments on commit 1760451

Please sign in to comment.
Something went wrong with that request. Please try again.