1 #ifndef __LINUX_PRIME_NUMBERS_H 2 #define __LINUX_PRIME_NUMBERS_H 3 4 #include <linux/types.h> 5 6 bool is_prime_number(unsigned long x); 7 unsigned long next_prime_number(unsigned long x); 8 9 /** 10 * for_each_prime_number - iterate over each prime upto a value 11 * @prime: the current prime number in this iteration 12 * @max: the upper limit 13 * 14 * Starting from the first prime number 2 iterate over each prime number up to 15 * the @max value. On each iteration, @prime is set to the current prime number. 16 * @max should be less than ULONG_MAX to ensure termination. To begin with 17 * @prime set to 1 on the first iteration use for_each_prime_number_from() 18 * instead. 19 */ 20 #define for_each_prime_number(prime, max) \ 21 for_each_prime_number_from((prime), 2, (max)) 22 23 /** 24 * for_each_prime_number_from - iterate over each prime upto a value 25 * @prime: the current prime number in this iteration 26 * @from: the initial value 27 * @max: the upper limit 28 * 29 * Starting from @from iterate over each successive prime number up to the 30 * @max value. On each iteration, @prime is set to the current prime number. 31 * @max should be less than ULONG_MAX, and @from less than @max, to ensure 32 * termination. 33 */ 34 #define for_each_prime_number_from(prime, from, max) \ 35 for (prime = (from); prime <= (max); prime = next_prime_number(prime)) 36 37 #endif /* !__LINUX_PRIME_NUMBERS_H */ 38