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 81414596ddc035f0d6ee74795ea15876dbe04c83
Author: Dana Jacobsen <d...@acm.org>
Date:   Tue May 13 23:55:06 2014 -0700

    Allow GMP binomial
---
 XS.xs                     | 2 +-
 lib/Math/Prime/Util/PP.pm | 5 +++++
 t/19-moebius.t            | 8 +++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/XS.xs b/XS.xs
index 4147ef5..15c8344 100644
--- a/XS.xs
+++ b/XS.xs
@@ -805,7 +805,7 @@ znorder(IN SV* sva, IN SV* svn)
     overflow:
     switch (ix) {
       case 0:  _vcallsub_with_gmp("znorder");  break;
-      case 1:  _vcallsub_with_gmp("binomial");  break;
+      case 1:  _vcallsub_with_pp("binomial");  break;
       case 2:  _vcallsub_with_pp("jordan_totient");  break;
       case 3:
       default: _vcallsub_with_pp("legendre_phi"); break;
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 9e3e1a6..816ecdb 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -1787,6 +1787,11 @@ sub kronecker {
 }
 sub binomial {
   my($n, $k) = @_;
+
+  if (defined &Math::Prime::Util::GMP::binomial && 
Math::Prime::Util::prime_get_config()->{'gmp'}) {
+    return Math::Prime::Util::_reftyped($_[0], 
Math::Prime::Util::GMP::binomial($n,$k));
+  }
+
   return 0 if $n >= 0 && ($k < 0 || $k > $n);
   return 0 if $n < 0  && $k < 0 && $k > $n;
   return 1 if $k == 0;        # Work around bug in old
diff --git a/t/19-moebius.t b/t/19-moebius.t
index aeb074e..f1c0ad7 100644
--- a/t/19-moebius.t
+++ b/t/19-moebius.t
@@ -456,7 +456,7 @@ plan tests => 0 + 1
                 + scalar(@valuations)
                 + 3 + scalar(@invmods)
                 + scalar(@vecsums)
-                + scalar(@binomials)
+                + 2 + scalar(@binomials)
                 + scalar(keys %powers)
                 + scalar(keys %primroots) + 2
                 + scalar(keys %jordan_totients)
@@ -686,6 +686,12 @@ foreach my $r (@binomials) {
   my($n, $k, $exp) = @$r;
   is( binomial($n,$k), $exp, "binomial($n,$k)) = $exp" );
 }
+is_deeply( [map { binomial(10, $_) } -15 .. 15],
+           [qw/0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 10 45 120 210 252 210 120 45 10 
1 0 0 0 0 0/],
+           "binomial(10,n) for n in -15 .. 15" );
+is_deeply( [map { binomial(-10, $_) } -15 .. 15],
+           [qw/-2002 715 -220 55 -10 1 0 0 0 0 0 0 0 0 0 1 -10 55 -220 715 
-2002 5005 -11440 24310 -48620 92378 -167960 293930 -497420 817190 -1307504/],
+           "binomial(10,n) for n in -15 .. 15" );
 
 sub cmp_closeto {
   my $got = shift;

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