From 2eb43769534644ef8af78e6a1fa70c755d41200b Mon Sep 17 00:00:00 2001 From: ast Date: Thu, 2 Oct 2014 21:36:37 +0000 Subject: 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 --- primes/pr_tbl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'primes/pr_tbl.c') diff --git a/primes/pr_tbl.c b/primes/pr_tbl.c index d45204a0..5e2f8134 100644 --- a/primes/pr_tbl.c +++ b/primes/pr_tbl.c @@ -1,4 +1,4 @@ -/* $NetBSD: pr_tbl.c,v 1.7 2003/08/07 09:37:33 agc Exp $ */ +/* $NetBSD: pr_tbl.c,v 1.8 2014/10/02 21:36:37 ast Exp $ */ /* * Copyright (c) 1989, 1993 @@ -37,24 +37,24 @@ #if 0 static char sccsid[] = "@(#)pr_tbl.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: pr_tbl.c,v 1.7 2003/08/07 09:37:33 agc Exp $"); +__RCSID("$NetBSD: pr_tbl.c,v 1.8 2014/10/02 21:36:37 ast Exp $"); #endif #endif /* not lint */ /* * prime - prime table * - * By: Landon Curt Noll chongo@toad.com, ...!{sun,tolsoft}!hoptoad!chongo + * By Landon Curt Noll, http://www.isthe.com/chongo/index.html /\oo/\ * - * chongo /\oo/\ - * - * We are able to sieve 2^32-1 because this table has primes up to 65537 + * We are able to sieve 2^32-1 because this table has primes up to 65537 * and 65537^2 > 2^32-1. */ +#include + #include "primes.h" -const ubig prime[] = { +const uint64_t prime[] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103, 107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199, 211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313, @@ -546,4 +546,4 @@ const ubig prime[] = { }; /* pr_limit - largest prime in the prime table */ -const ubig *pr_limit = &prime[(sizeof(prime)/sizeof(prime[0]))-1]; +const uint64_t *const pr_limit = &prime[(sizeof(prime)/sizeof(prime[0]))-1]; -- cgit v1.2.3