[libmath-prime-util-perl] 08/25: 32-bit fixes

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


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

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

commit e70627587edfc308224cec2be7fe4975038f27df
Author: Dana Jacobsen <dana at acm.org>
Date:   Fri Nov 22 19:31:55 2013 -0800

    32-bit fixes
---
 lib/Math/Prime/Util/PP.pm | 11 +++++++++--
 xt/test-nthapprox.pl      | 24 +++++++++++++-----------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index add2d00..f48064b 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -522,10 +522,17 @@ sub _count_with_sieve {
 sub _lehmer_pi {
   my $x = shift;
   return _sieve_prime_count($x) if $x < 1_000;
-  my $z = int(sqrt($x+0.5));
+  my $z = (ref($x) ne 'Math::BigInt')
+        ? int(sqrt($x+0.5))
+        : int(Math::BigFloat->new($x)->badd(0.5)->bsqrt->bfloor->bstr);
   my $a = _lehmer_pi(int(sqrt($z)+0.5));
   my $b = _lehmer_pi($z);
-  my $c = _lehmer_pi(int($x**(1/3)+0.5));
+  my $c = _lehmer_pi(int( (ref($x) ne 'Math::BigInt')
+                          ? $x**(1/3)+0.5
+                          : Math::BigFloat->new($x)->broot(3)->badd(0.5)->bfloor
+                     ));
+  ($z, $a, $b, $c) = map { (ref($_) =~ /^Math::Big/) ? int($_->bstr) : $_ }
+                     ($z, $a, $b, $c);
 
   # Generate at least b primes.
   my $bth_prime_upper = ($b <= 10) ? 29 : int($b*(log($b) + log(log($b)))) + 1;
diff --git a/xt/test-nthapprox.pl b/xt/test-nthapprox.pl
index 20b6490..e8e862e 100755
--- a/xt/test-nthapprox.pl
+++ b/xt/test-nthapprox.pl
@@ -2,6 +2,7 @@
 use strict;
 use warnings;
 use Math::Prime::Util ":all";
+use Math::BigFloat;
 $| = 1;  # fast pipes
 
 my %nthprimes = (
@@ -18,20 +19,21 @@ my %nthprimes = (
         10000000000 => 252097800623,
        100000000000 => 2760727302517,
       1000000000000 => 29996224275833,
-     10000000000000 => 323780508946331,
-    100000000000000 => 3475385758524527,
-   1000000000000000 => 37124508045065437,
-  10000000000000000 => 394906913903735329,
- 100000000000000000 => 4185296581467695669,
+     '10000000000000' => 323780508946331,
+    '100000000000000' => 3475385758524527,
+   '1000000000000000' => 37124508045065437,
+  '10000000000000000' => 394906913903735329,
+ '100000000000000000' => 4185296581467695669,
 );
 
 printf("  N    %12s  %12s\n", "nth_approx", "percent");
 printf("-----  %12s  %12s\n", '-'x12, '-'x12);
 foreach my $n (sort {$a<=>$b} keys %nthprimes) {
-  my $nth  = $nthprimes{$n};
-  my $ntha = nth_prime_approx($n);
+  my ($nth, $ntha) =
+    map { Math::BigFloat->new($_) }
+    ($nthprimes{$n}, nth_prime_approx($n));
 
-  printf "10^%2d %13lu  %12.7f\n", length($n)-1, abs($nth-$ntha), 100*($ntha-$nth)/$nth;
+  printf "10^%2d %13s  %12.7f\n", length($n)-1, abs($nth-$ntha), 100*($ntha-$nth)/$nth;
 }
 
 print "\n";
@@ -41,9 +43,9 @@ print "\n";
 printf("  N    %12s  %12s\n", "lower", "upper");
 printf("-----  %12s  %12s\n", '-'x12,'-'x12);
 foreach my $n (sort {$a<=>$b} keys %nthprimes) {
-  my $nth  = $nthprimes{$n};
-  my $nthl  = nth_prime_lower($n);
-  my $nthu  = nth_prime_upper($n);
+  my ($nth, $nthl, $nthu) =
+    map { Math::BigFloat->new($_) }
+    ($nthprimes{$n}, nth_prime_lower($n), nth_prime_upper($n));
 
   printf "10^%2d  %12.7f  %12.7f\n",
          length($n)-1, 100.0*($nth-$nthl)/$nth, 100.0*($nthu-$nth)/$nth;

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