This is an automated email from the git hooks/post-receive script. ppm-guest pushed a commit to annotated tag v0.23 in repository libmath-prime-util-perl.
commit fe9a34d00b0583c552f5bf329f3a26b0018d3fbe Author: Dana Jacobsen <d...@acm.org> Date: Mon Mar 4 05:27:13 2013 -0800 Fix divisor sum on bigints --- lib/Math/Prime/Util.pm | 5 +++-- t/81-bignum.t | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm index ec4dd9e..c072b9e 100644 --- a/lib/Math/Prime/Util.pm +++ b/lib/Math/Prime/Util.pm @@ -1297,11 +1297,12 @@ sub divisor_sum { if (!defined $sub) { return _XS_divisor_sum($n) if $n <= $_XS_MAXVAL; - my $product = 1; + my $bone = (ref($n) eq 'Math::BigInt') ? $n->copy->bone : 1; + my $product = $bone; my @factors = factor($n); while (@factors) { if (@factors > 1 && $factors[0] == $factors[1]) { - my $fmult = $factors[0] * $factors[0]; + my $fmult = $bone * $factors[0] * $factors[0]; $fmult *= shift @factors while @factors > 1 && $factors[0] == $factors[1]; $product *= ($fmult -1) / ($factors[0] - 1); } else { diff --git a/t/81-bignum.t b/t/81-bignum.t index 96e5baa..7665c40 100644 --- a/t/81-bignum.t +++ b/t/81-bignum.t @@ -74,7 +74,7 @@ plan tests => 0 + 6*2*$extra # more PC tests + scalar(keys %factors) + scalar(keys %allfactors) - + 4 # moebius, euler_phi, jordan totient + + 5 # moebius, euler_phi, jordan totient + 15 # random primes + 0; @@ -209,6 +209,9 @@ SKIP: { $n = 48981631802481400359696467; is( jordan_totient(5,$n), 281946200770875813001683560563488308767928594805846855593191749929654015729263525162226378019837608857421063724603387506651820000, "jordan_totient(5,$n)" ); is( divisor_sum( $n, sub { my $d=shift; $d**5 * moebius($n/$d); }), 281946200770875813001683560563488308767928594805846855593191749929654015729263525162226378019837608857421063724603387506651820000, "jordan totient using divisor_sum and moebius" ); + # Done wrong, the following will have a bunch of extra zeros. + my $hundredfac = Math::BigInt->new(100)->bfac; + is( divisor_sum($hundredfac), 774026292208877355243820142464115597282472420387824628823543695735957009720184359087194959566149232506852422409529601312686157396490982598473425595924480000000, "Divisor sum of 100!" ); } ############################################################################### -- 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