[libmath-prime-util-perl] 26/50: Speed up powmod a tiny bit
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:45:36 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.13
in repository libmath-prime-util-perl.
commit b3e35faa723f93d6f47954a0848fdbe5cb6864cf
Author: Dana Jacobsen <dana at acm.org>
Date: Sat Oct 27 18:48:45 2012 -0700
Speed up powmod a tiny bit
---
lib/Math/Prime/Util/PP.pm | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 515b9fb..0cf7657 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -493,9 +493,9 @@ sub _native_powmod {
my $t = 1;
$n = $n % $m;
while ($power) {
- $t = ($t * $n) % $m if ($power & 1) != 0;
- $n = ($n * $n) % $m;
+ $t = ($t * $n) % $m if ($power & 1);
$power >>= 1;
+ $n = ($n * $n) % $m if $power;
}
$t;
}
@@ -507,15 +507,15 @@ sub _powmod {
if ($m < $_half_word) {
$n %= $m;
while ($power) {
- $t = ($t * $n) % $m if ($power & 1) != 0;
- $n = ($n * $n) % $m;
+ $t = ($t * $n) % $m if ($power & 1);
$power >>= 1;
+ $n = ($n * $n) % $m if $power;
}
} else {
while ($power) {
- $t = _mulmod($t, $n, $m) if ($power & 1) != 0;
- $n = _mulmod($n, $n, $m);
+ $t = _mulmod($t, $n, $m) if ($power & 1);
$power >>= 1;
+ $n = _mulmod($n, $n, $m) if $power;
}
}
$t;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list