2 * UCW Library -- Prime Number Table
4 * (c) 2005 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "lib/binsearch.h"
13 /* A table of odd primes, each is about 1.2 times the previous one */
14 static uns prime_table[] = {
122 #define NPRIMES ARRAY_SIZE(prime_table)
125 next_table_prime(uns x)
127 if (x >= prime_table[NPRIMES-1])
130 return prime_table[BIN_SEARCH_FIRST_GE(prime_table, NPRIMES, x+1)];
134 prev_table_prime(uns x)
136 int i = BIN_SEARCH_FIRST_GE(prime_table, NPRIMES, x);
137 return i ? prime_table[i-1] : 0;
146 #if 0 /* Generate the table */
152 x = nextprime(1.2*x);
156 for (int i=1; i<=100; i++)
157 printf("%d\t%d\t%d\n", i, next_table_prime(i), prev_table_prime(i));
158 for (uns i=0xfffffff0; i; i++)
159 printf("%u\t%u\t%u\n", i, next_table_prime(i), prev_table_prime(i));