1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __LINUX_PRIME_NUMBERS_H 2 #ifndef __LINUX_PRIME_NUMBERS_H 3 #define __LINUX_PRIME_NUMBERS_H 3 #define __LINUX_PRIME_NUMBERS_H 4 4 5 #include <linux/types.h> 5 #include <linux/types.h> 6 6 7 bool is_prime_number(unsigned long x); 7 bool is_prime_number(unsigned long x); 8 unsigned long next_prime_number(unsigned long 8 unsigned long next_prime_number(unsigned long x); 9 9 10 /** 10 /** 11 * for_each_prime_number - iterate over each p 11 * for_each_prime_number - iterate over each prime upto a value 12 * @prime: the current prime number in this it 12 * @prime: the current prime number in this iteration 13 * @max: the upper limit 13 * @max: the upper limit 14 * 14 * 15 * Starting from the first prime number 2 iter 15 * Starting from the first prime number 2 iterate over each prime number up to 16 * the @max value. On each iteration, @prime i 16 * the @max value. On each iteration, @prime is set to the current prime number. 17 * @max should be less than ULONG_MAX to ensur 17 * @max should be less than ULONG_MAX to ensure termination. To begin with 18 * @prime set to 1 on the first iteration use 18 * @prime set to 1 on the first iteration use for_each_prime_number_from() 19 * instead. 19 * instead. 20 */ 20 */ 21 #define for_each_prime_number(prime, max) \ 21 #define for_each_prime_number(prime, max) \ 22 for_each_prime_number_from((prime), 2, 22 for_each_prime_number_from((prime), 2, (max)) 23 23 24 /** 24 /** 25 * for_each_prime_number_from - iterate over e 25 * for_each_prime_number_from - iterate over each prime upto a value 26 * @prime: the current prime number in this it 26 * @prime: the current prime number in this iteration 27 * @from: the initial value 27 * @from: the initial value 28 * @max: the upper limit 28 * @max: the upper limit 29 * 29 * 30 * Starting from @from iterate over each succe 30 * Starting from @from iterate over each successive prime number up to the 31 * @max value. On each iteration, @prime is se 31 * @max value. On each iteration, @prime is set to the current prime number. 32 * @max should be less than ULONG_MAX, and @fr 32 * @max should be less than ULONG_MAX, and @from less than @max, to ensure 33 * termination. 33 * termination. 34 */ 34 */ 35 #define for_each_prime_number_from(prime, from 35 #define for_each_prime_number_from(prime, from, max) \ 36 for (prime = (from); prime <= (max); p 36 for (prime = (from); prime <= (max); prime = next_prime_number(prime)) 37 37 38 #endif /* !__LINUX_PRIME_NUMBERS_H */ 38 #endif /* !__LINUX_PRIME_NUMBERS_H */ 39 39
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.