[libmath-prime-util-perl] 46/55: Fix for old Math::BigInt and negative args

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:53:43 UTC 2015


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 a6fd1c9132ea9a36fe8ba84643832b1b539fea4e
Author: Dana Jacobsen <dana at acm.org>
Date:   Wed May 14 10:45:04 2014 -0700

    Fix for old Math::BigInt and negative args
---
 lib/Math/Prime/Util/PP.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 816ecdb..fb11665 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -1793,7 +1793,10 @@ sub binomial {
   }
 
   return 0 if $n >= 0 && ($k < 0 || $k > $n);
-  return 0 if $n < 0  && $k < 0 && $k > $n;
+  if ($n < 0 && $k < 0) {
+    return 0 if $k > $n;
+    $k = $n-$k;
+  }
   return 1 if $k == 0;        # Work around bug in old
   return $n if $k == $n-1;    # Math::BigInt (fixed in 1.90)
   my $r;
@@ -1801,7 +1804,6 @@ sub binomial {
     $r = Math::BigInt->new("$n")->bnok("$k");
     $r = _bigint_to_int($r) if $r->bacmp(''.~0) <= 0;
   } else { # Math::BigInt is incorrect for negative n
-    $k = $n-$k if $k < 0;
     $r = Math::BigInt->new( ''.(-$n+$k-1) )->bnok("$k");
     if ($k & 1) {
       $r->bneg;

-- 
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