The library defines some simple functions to generate prime numbers. They are useful for example in hash tables.


int isprime(uint x);

Return a non-zero value iff x is a prime number. The time complexity is O(sqrt(x)).


uint nextprime(uint x);

Return some prime greater than x. The function does not checks overflows, but it should be safe at least for x lower than 1U << 31. If the Cramer’s conjecture is true, it should have complexity O(sqrt(x) * log(x)^2).


uint next_table_prime(uint x);

Quickly lookup a precomputed table to return a prime number greater than x. Returns zero if there is no such prime (we guarantee the existance of at least one prime greater than 1U << 31 in the table).


uint prev_table_prime(uint x);

Quickly lookup a precomputed table to return a prime number smaller than x. Returns zero if x is smaller than 7.