This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.41
in repository libmath-prime-util-perl.

commit 6c549731d2d71bc9942730d12f81efd031c54595
Author: Dana Jacobsen <d...@acm.org>
Date:   Sat May 17 22:11:49 2014 -0700

    Allow better optimization for invmod and large modulus
---
 lib/Math/Prime/Util/PP.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index f04a8fb..07a78b8 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -1528,16 +1528,16 @@ sub invmod {
   return if $n == 0 || $a == 0;
   return 0 if $n == 1;
   $n = -$n if $n < 0;  # Pari semantics
-  if ($n > (~0>>1)) {
+  if ($n > ~0) {
     my $invmod = Math::BigInt->new("$a")->bmodinv("$n");
     return if !defined $invmod || $invmod->is_nan;
     $invmod = _bigint_to_int($invmod) if $invmod->bacmp(''.~0) <= 0;
     return $invmod;
   }
-  my($t,$nt,$r,$nr) = (0, 1, $n, $a);
-  use integer;
+  my($t,$nt,$r,$nr) = (0, 1, $n, $a % $n);
   while ($nr != 0) {
-    my $quot = int($r/$nr);
+    # Use mod before divide to force correct behavior with high bit set
+    my $quot = int( ($r-($r % $nr))/$nr );
     ($nt,$t) = ($t-$quot*$nt,$nt);
     ($nr,$r) = ($r-$quot*$nr,$nr);
   }

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to