[libmath-prime-util-perl] 54/54: Partitions uses Math::BigInt only when needed

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


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

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

commit 9230a69ec56a29d9155750fbcfe24e0a291879df
Author: Dana Jacobsen <dana at acm.org>
Date:   Fri Feb 28 19:27:35 2014 -0800

    Partitions uses Math::BigInt only when needed
---
 lib/Math/Prime/Util/PP.pm | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index b3629cf..bcc2226 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -535,13 +535,14 @@ sub partitions {
 
   my $d = int(sqrt($n+1));
   my @pent = (1, map { (($_*(3*$_+1))>>1, (($_+1)*(3*$_+2))>>1) } 1 .. $d);
-  my @part = (Math::BigInt->bone);
+  my $ZERO = ($n >= ((~0 > 4294967295) ? 400 : 270)) ? BZERO : 0;
+  my @part = ($ZERO+1);
   foreach my $j (scalar @part .. $n) {
-    my ($psum1, $psum2, $k) = (Math::BigInt->bzero, Math::BigInt->bzero, 1);
+    my ($psum1, $psum2, $k) = ($ZERO, $ZERO, 1);
     foreach my $p (@pent) {
       last if $p > $j;
-      if ((++$k) & 2) { $psum1->badd( $part[ $j - $p ] ); }
-      else            { $psum2->badd( $part[ $j - $p ] ); }
+      if ((++$k) & 2) { $psum1 += $part[ $j - $p ] }
+      else            { $psum2 += $part[ $j - $p ] }
     }
     $part[$j] = $psum1 - $psum2;
   }

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