56static inline
void *nut_Pitcharr_get(
void *buf,
size_t pitch, uint64_t i){
68static inline
bool nut_Bitarray_get(const uint8_t *buf, uint64_t i){
69 return buf[i/8] & (UINT8_C(1) << (i%8));
78static inline
void nut_Bitarray_set(uint8_t *buf, uint64_t i,
bool v){
80 buf[i/8] |= 1ull << (i%8);
82 buf[i/8] &= ~(UINT8_C(1) << (i%8));
95static inline uint8_t nut_Bitfield2_arr_get(const uint8_t *buf, uint64_t i){
96 return (buf[i/4] >> (i%4*2)) & 3;
107bool nut_u64_make_factorial_tbl(uint64_t k, uint64_t modulus, uint64_t bits, uint64_t max_denom, uint64_t factorials[
static bits + k], uint64_t inv_factorials[
static max_denom + 1]);
121[[deprecated(
"Replace with nut_sieve_smallest_factors_wheel6")]]
#define NUT_ATTR_RETURNS_NONNULL
Wrapper for gnu::returns_nonnull attr.
#define NUT_ATTR_NO_SAN(name)
Prevent clang from reporting spurious errors when a length zero array is passed to a length annotated...
#define NUT_ATTR_ACCESS(...)
Wrapper for gcc's access function annotation - no clang equivalent, and currently disabled because it...
#define NUT_ATTR_NONNULL(...)
Wrapper for gnu::nonnull attr.
#define NUT_ATTR_PURE
Wrapper for gnu::pure attr - similar to const but the function can read non-volatile memory (includin...
#define NUT_ATTR_CONST
Wrapper for gnu::const attr - such a function has no side effects and cannot read memory.
#define NUT_ATTR_MALLOC
Wrapper for gnu::malloc attr - indicates the function returns a malloc'd pointer that must be free'd.
NUT_ATTR_MALLOC uint8_t * nut_sieve_omega(uint64_t max)
Compute the number of distinct prime divisors of every number in the range from 0 to max.
NUT_ATTR_MALLOC uint8_t * nut_sieve_mobius(uint64_t max)
Compute the Mobius function for every number from 0 to max.
NUT_ATTR_MALLOC uint64_t * nut_sieve_carmichael(uint64_t max)
Compute the Carmichael function for every number from 0 to max.
NUT_ATTR_MALLOC uint64_t * nut_sieve_sigma_e(uint64_t max, uint64_t e)
Compute the sum of some power of divisors (including 1 and n) for every number n from 0 to max.
NUT_ATTR_MALLOC uint8_t * nut_sieve_is_composite(uint64_t max)
Compute a bitarray of whether or not each number from 0 to max is composite.
NUT_ATTR_PURE bool nut_is_composite(uint64_t n, const uint8_t buf[static n/30+1])
Check if a number is composite using a packed bitarray from nut_sieve_is_composite.
NUT_ATTR_MALLOC void * nut_sieve_factorizations(uint64_t max, uint64_t *_w)
Compute the factorization for every number in the range from 0 to max.
NUT_ATTR_MALLOC uint64_t * nut_compute_pi_range(uint64_t max, const uint8_t buf[static max/30+1])
Compute the pi (prime counting) function for every number from 0 to max.
NUT_ATTR_MALLOC int64_t * nut_compute_mertens_range(uint64_t max, const uint8_t mobius[static max/4+1])
Compute the Mertens function (sum of Mobius function) for every number from 0 to max.
NUT_ATTR_CONST uint64_t nut_max_primes_le(uint64_t max)
Compute an upper bound on the number of primes up to max.
NUT_ATTR_CONST uint64_t nut_get_factors_pitch(uint64_t w)
Get the pitch for a pitched array of nut_u64_Pitcharr factor lists.
bool nut_u64_make_factorial_tbl(uint64_t k, uint64_t modulus, uint64_t bits, uint64_t max_denom, uint64_t factorials[static bits+k], uint64_t inv_factorials[static max_denom+1])
Calculate factorials and inverse factorials for a given upper bound and modulus.
NUT_ATTR_MALLOC uint64_t * nut_sieve_sigma_1(uint64_t max)
Compute the sum of divisors (including 1 and n) for every number n from 0 to max.
NUT_ATTR_MALLOC void * nut_sieve_factors(uint64_t max, uint64_t *_w)
Compute the unique prime factors of every number in the range from 0 to max.
NUT_ATTR_CONST uint64_t nut_max_prime_divs(uint64_t max)
Compute the maximum number of unique prime divisors a number can have.
NUT_ATTR_MALLOC uint64_t * nut_sieve_phi(uint64_t max)
Compute Euler's totient function for every number from 0 to max.
void nut_fill_factors_from_smallest_wheel6(nut_Factors *restrict out, uint64_t n, const uint32_t smallest_factors[restrict static n/3+1])
Use a table of smallest prime factors for a wheel of 6 to get the factorization of a number.
NUT_ATTR_MALLOC uint64_t * nut_sieve_sigma_0(uint64_t max)
Compute the number of divisors (including 1 and n) for every number n from 0 to max.
NUT_ATTR_MALLOC uint64_t * nut_sieve_largest_factors(uint64_t max)
Compute the largest prime factor of every number in the range from 0 to max.
NUT_ATTR_CONST uint64_t nut_get_factorizations_pitch(uint64_t w)
Get the pitch for a pitched array of factorization structs with w unique prime divisors.
void nut_fill_factors_from_largest(nut_Factors *restrict out, uint64_t n, const uint64_t largest_factors[restrict static n+1])
Use a table of largest prime factors to get the factorization of a number.
NUT_ATTR_MALLOC uint64_t * nut_sieve_dk(uint64_t max, uint64_t k, uint64_t modulus)
Compute the generalized divisor function dk(n) (number of k-tuples with product n) for every number n...
NUT_ATTR_PURE uint64_t nut_compute_pi_from_tables(uint64_t n, const uint64_t pi_table[restrict static n/30], const uint8_t buf[restrict static n/30+1])
Get the value for the pi (prime counting) function for a particular number using precomputed tables.
NUT_ATTR_MALLOC uint32_t * nut_sieve_smallest_factors_wheel6(uint64_t max)
Compute the smallest prime factor of every number coprime to 6 in the range from 0 to max,...
NUT_ATTR_MALLOC uint32_t * nut_sieve_smallest_factors(uint64_t max)
Compute the smallest prime factor of every number in the range from 0 to max, or 1 for primes Compare...
void nut_fill_factors_from_smallest(nut_Factors *restrict out, uint64_t n, const uint32_t smallest_factors[restrict static n+1])
Use a table of smallest prime factors to get the factorization of a number.
NUT_ATTR_MALLOC uint64_t * nut_sieve_primes(uint64_t max, uint64_t *_num_primes)
Compute an array of all primes from 0 to max.