[libmath-prime-util-perl] 18/23: Fixes for various compile / test issues
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:45:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.14
in repository libmath-prime-util-perl.
commit 6695c65c1d2694108dbc23970b7c2497f2ccbabb
Author: Dana Jacobsen <dana at acm.org>
Date: Thu Nov 29 13:50:28 2012 -0800
Fixes for various compile / test issues
---
aks.c | 3 +--
lehmer.c | 8 ++++----
lib/Math/Prime/Util.pm | 6 +++---
lib/Math/Prime/Util/ZetaBigFloat.pm | 4 ++--
t/22-aks-prime.t | 6 +++++-
t/31-threading.t | 6 +++++-
util.c | 37 +++++++++++++++++++++++++------------
7 files changed, 45 insertions(+), 25 deletions(-)
diff --git a/aks.c b/aks.c
index 26cfd4a..ee48331 100644
--- a/aks.c
+++ b/aks.c
@@ -42,9 +42,8 @@ static int is_perfect_power(UV x) {
UV b, last;
if ((x & (x-1)) == 0) return 1; /* powers of 2 */
b = sqrt(x); if (b*b == x) return 1; /* perfect square */
- b = cbrt(x); if (b*b*b == x) return 1; /* perfect cube */
last = log2floor(x) + 1;
- for (b = 5; b < last; b = _XS_next_prime(b)) {
+ for (b = 3; b < last; b = _XS_next_prime(b)) {
UV root = pow(x, 1.0 / (double)b);
if (pow(root, b) == x) return 1;
}
diff --git a/lehmer.c b/lehmer.c
index facc3d7..6bb5d59 100644
--- a/lehmer.c
+++ b/lehmer.c
@@ -137,7 +137,7 @@ static UV* generate_small_primes(UV n)
UV i, nth_prime;
/* Dusart 1999 bound */
- nth_prime = (n <= 10) ? 29 : n * ( log(n) + log(log(n)) ) + 1;
+ nth_prime = (n <= 10) ? 29 : (UV) (n * ( log(n) + log(log(n)) )) + 1;
if (get_prime_cache(nth_prime, &sieve) < nth_prime) {
release_prime_cache(sieve);
@@ -293,7 +293,7 @@ static void heap_insert(heap_t* h, UV val, IV count)
if (verbose>2) printf("ALLOCing heap, size %lu\n", new_size);
New(0, h->array, new_size, vc_t);
} else {
- new_size = 1.5 * h->array_size;
+ new_size = (UV) (1.5 * h->array_size);
if (verbose>2) printf("REALLOCing heap %p, new size %lu\n", h->array, new_size);
Renew( h->array, new_size, vc_t );
}
@@ -454,7 +454,7 @@ UV _XS_legendre_pi(UV n)
if (n < SIEVE_LIMIT)
return _XS_prime_count(2, n);
- a = _XS_legendre_pi(sqrt(n)+0.5);
+ a = _XS_legendre_pi( (UV) (sqrt(n)+0.5) );
return phi(n, a) + a - 1;
}
@@ -523,7 +523,7 @@ UV _XS_lehmer_pi(UV n)
if (verbose > 0) printf("lehmer %lu stage 1: calculate a,b,c \n", n);
TIMING_START;
- z = sqrt((double)n+0.5);
+ z = (UV) sqrt((double)n+0.5);
a = _XS_lehmer_pi(sqrt((double)z)+0.5); /* a = floor(n^1/4) */
b = _XS_lehmer_pi(z); /* b = floor(n^1/2) */
c = _XS_lehmer_pi(pow((double)n, 1.0/3.0)+0.5); /* c = floor(n^1/3) */
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 30041a2..f8fe583 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -214,7 +214,7 @@ sub _upgrade_to_float {
return $n unless defined $Math::BigInt::VERSION || defined $Math::BigFloat::VERSION;
do { require Math::BigFloat; Math::BigFloat->import() }
if defined $Math::BigInt::VERSION && !defined $Math::BigFloat::VERSION;
- return Math::BigFloat->new($n);
+ return Math::BigFloat->new($n); # $n is a Math::BigInt
}
my @_primes_small = (
@@ -604,7 +604,7 @@ sub primes {
if ($k > 2*$m) {
my $rbits = 0;
while ($rbits <= $m) {
- my $s = Math::BigFloat->new( $irandf->($rand_max_val) )->bdiv($rand_max_val);
+ my $s = Math::BigFloat->new( "$irandf->($rand_max_val)" )->bdiv($rand_max_val);
my $r = Math::BigFloat->new(2)->bpow($s-1);
$rbits = $k - ($r*$k);
}
@@ -1121,7 +1121,7 @@ sub is_provable_prime {
}
for (my $a = 2; $a < $nm1; $a++) {
- my $ap = Math::BigInt->new($a);
+ my $ap = Math::BigInt->new("$a");
# 1. a^(n-1) = 1 mod n.
next if $ap->copy->bmodpow($nm1, $n) != 1;
# 2. a^((n-1)/f) != 1 mod n for all f.
diff --git a/lib/Math/Prime/Util/ZetaBigFloat.pm b/lib/Math/Prime/Util/ZetaBigFloat.pm
index 01cd860..05aa3d2 100644
--- a/lib/Math/Prime/Util/ZetaBigFloat.pm
+++ b/lib/Math/Prime/Util/ZetaBigFloat.pm
@@ -299,9 +299,9 @@ sub RiemannZeta {
# into (6^-(40.5/4))^4 (assuming the base is positive). Without that hack,
# none of this would work at all.
- $x = Math::BigFloat->new($x);
+ $x = Math::BigFloat->new("$x");
my $superx = 1;
- my $subx = Math::BigFloat->new($x);
+ my $subx = $x->copy;
while ($subx > 8) {
$superx *= 2;
$subx /= 2;
diff --git a/t/22-aks-prime.t b/t/22-aks-prime.t
index 2d68eb0..355bde6 100644
--- a/t/22-aks-prime.t
+++ b/t/22-aks-prime.t
@@ -54,9 +54,13 @@ ok(!is_aks_prime(0), '0 is not prime');
ok(!is_aks_prime(-1), '-1 is not prime');
ok(!is_aks_prime(-2), '-2 is not prime');
-# Simple number (cought by sqrt test
+# Simple number (cought by sqrt test)
is( is_aks_prime(877), 1, "is_aks_prime(877) is true" );
+# Perhaps let them know this is probably not a hung test?
+# This runs in milliseconds on an i3930K, but many seconds on an UltraSPARC.
+#diag "Unfortunately these tests are very slow.";
+
# The first number that makes it past the sqrt test to actually run.
is( is_aks_prime(69197), 1, "is_aks_prime(69197) is true" );
diff --git a/t/31-threading.t b/t/31-threading.t
index 8a13452..100af72 100644
--- a/t/31-threading.t
+++ b/t/31-threading.t
@@ -9,11 +9,15 @@ BEGIN {
exit(0);
}
# All these tests used to run on Cygwin, but now they're all giving me
- # random panics in mutexes.
+ # random panics in mutexes. Same with NetBSD.
if ($Config{osname} eq 'cygwin') {
print "1..0 # Skip Cygwin threads are unstable\n";
exit 0;
}
+ if ($Config{osname} eq 'netbsd') {
+ print "1..0 # Skip NetBSD threads have panic issues\n";
+ exit 0;
+ }
# Should be be looking for newer than 5.008?
if (! eval { require threads }) {
print "1..0 # Skip threads.pm not installed\n";
diff --git a/util.c b/util.c
index 3254cf6..a67b506 100644
--- a/util.c
+++ b/util.c
@@ -10,20 +10,33 @@
* Noting that 'long double' on many platforms is no different than 'double'
* so it may buy us nothing. But it's worth trying.
*/
-extern long double powl(long double, long double);
-extern long double expl(long double);
-extern long double logl(long double);
-extern long double fabsl(long double);
-
-/* However, standard math functions weren't defined on them until C99. Same
- * with the macro INFINITY. There are some reasonable platforms I've seen
- * that don't have these. */
+
+/* These math functions are a clusterfrack. They're defined by C99, but
+ * NetBSD doesn't have them. You need them in both the headers and libraries,
+ * but there is no standard way to find out if the libraries have them. The
+ * best way (I belive) to deal with this is having the make system do test
+ * compiles. Barring that, we make limited guesses, and just give up
+ * precision on any system we don't recognize.
+ */
+#if _MSC_VER
+ /* MSVS has these as macros, and really doesn't want us defining them. */
+#elif defined(__MATH_DECLARE_LDOUBLE) || \
+ defined(__LONG_DOUBLE_128__) || \
+ defined(__LONGDOUBLE128)
+ /* GLIBC */
+ extern long double powl(long double, long double);
+ extern long double expl(long double);
+ extern long double logl(long double);
+ extern long double fabsl(long double);
+#else
+ #define powl(x, y) (long double) pow( (double) (x), (double) (y) )
+ #define expl(x) (long double) exp( (double) (x) )
+ #define logl(x) (long double) log( (double) (x) )
+ #define fabsl(x) (long double) fabs( (double) (x) )
+#endif
+
#ifndef INFINITY
#define INFINITY (DBL_MAX + DBL_MAX)
- #define powl(x, y) (long double) pow( (double) (x), (double) (y) )
- #define expl(x) (long double) exp( (double) (x) )
- #define logl(x) (long double) log( (double) (x) )
- #define fabsl(x) (long double) fabs( (double) (x) )
#endif
#include "ptypes.h"
--
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