summaryrefslogtreecommitdiffstats
path: root/primes/pattern.c
diff options
context:
space:
mode:
authorast <ast@NetBSD.org>2014-10-02 21:36:37 +0000
committerast <ast@NetBSD.org>2014-10-02 21:36:37 +0000
commit2eb43769534644ef8af78e6a1fa70c755d41200b (patch)
treef39dbbb28c3e53e18a61d031583f9cccc1c89416 /primes/pattern.c
parentd43706be7b336fd46d5a93d300182a17193f5544 (diff)
downloadbsdgames-darwin-2eb43769534644ef8af78e6a1fa70c755d41200b.tar.gz
bsdgames-darwin-2eb43769534644ef8af78e6a1fa70c755d41200b.tar.zst
bsdgames-darwin-2eb43769534644ef8af78e6a1fa70c755d41200b.zip
Imported and adapted from FreeBSD svn r272166 and r272207; this fixes
false positives for products of primes larger than 2^16. For example, before this commit: $ /usr/games/primes 4295360521 4295360522 4295360521 but $ /usr/games/factor 4295360521 4295360521: 65539 65539 or $ /usr/games/primes 3825123056546413049 3825123056546413050 3825123056546413049 yet $ /usr/games/factor 3825123056546413049 3825123056546413049: 165479 23115459100831 or $ /usr/games/primes 18446744073709551577 18446744073709551577 although $ /usr/games/factor 18446744073709551577 18446744073709551577: 139646831 132095686967 Incidentally, the above examples show the smallest and largest cases that were erroneously stated as prime in the range 2^32 .. 3825123056546413049 .. 2^64; the primes(6) program now stops at 3825123056546413050 as primality tests on larger integers would be by brute force factorization. In addition, special to the NetBSD version: . for -d option, skip first difference when start is >65537 as it is incorrect . corrected usage to mention both the existing -d as well as the new -h option For original FreeBSD commit message by Colin Percival, see: http://svnweb.freebsd.org/base?view=revision&revision=272166
Diffstat (limited to 'primes/pattern.c')
-rw-r--r--primes/pattern.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/primes/pattern.c b/primes/pattern.c
index 11960567..52784a5a 100644
--- a/primes/pattern.c
+++ b/primes/pattern.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pattern.c,v 1.6 2003/08/07 09:37:33 agc Exp $ */
+/* $NetBSD: pattern.c,v 1.7 2014/10/02 21:36:37 ast Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -32,21 +32,20 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#include <sys/types.h>
+
#ifndef lint
#if 0
static char sccsid[] = "@(#)pattern.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: pattern.c,v 1.6 2003/08/07 09:37:33 agc Exp $");
+__RCSID("$NetBSD: pattern.c,v 1.7 2014/10/02 21:36:37 ast Exp $");
#endif
#endif /* not lint */
/*
* pattern - the Eratosthenes sieve on odd numbers for 3,5,7,11 and 13
*
- * By: Landon Curt Noll chongo@toad.com
- *
- * chongo <for a good prime call: 391581 * 2^216193 - 1> /\oo/\
+ * By Landon Curt Noll, http://www.isthe.com/chongo/index.html /\oo/\
*
* To avoid excessive sieves for small factors, we use the table below to
* setup our sieve blocks. Each element represents a odd number starting
@@ -440,4 +439,4 @@ const char pattern[] = {
0,0,1,1,0,0,0,0,1,1,0,0,1,0,1,0,0,0,0,0,0,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,
0,0,1,1,0,1,0,0,1,1,0,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,0,0,0,0,0,1
};
-const int pattern_size = (sizeof(pattern)/sizeof(pattern[0]));
+const size_t pattern_size = (sizeof(pattern)/sizeof(pattern[0]));