X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fprime.h;h=87d13f92ed4fe285ae3925a411bd90b0e609b83c;hb=634be141f3f014e31d5931a968c0c0f7e07205fb;hp=9ca2a01ebce72d48c2cdf878c8dc5d2e46ef2f87;hpb=689b60e4c61d300b576fdb7007de51189d2f0f7e;p=libucw.git diff --git a/ucw/prime.h b/ucw/prime.h index 9ca2a01e..87d13f92 100644 --- a/ucw/prime.h +++ b/ucw/prime.h @@ -21,12 +21,32 @@ /* prime.c */ +/** + * Return a non-zero value iff @x is a prime number. + * The time complexity is `O(sqrt(x))`. + **/ int isprime(uns 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)`. + **/ uns nextprime(uns x); /* primetable.c */ +/** + * 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). + **/ uns next_table_prime(uns x); + +/** + * Quickly lookup a precomputed table to return a prime number smaller than @x. + * Returns zero if @x is smaller than `7`. + **/ uns prev_table_prime(uns x); #endif // _UCW_PRIME_H