The code in mpz/primorial_ui.c and tests/devel/primes.c is fairly self-documenting but I added this comment to gmp-impl.h
-/* primesieve macros and functions */ +/* + * primesieve macros and functions + * + * These macros are used to iterate over primes found by gmp_primesieve + * which are stored in a compact bit format (excluding multiples of 2 and 3). + * + * See mpz/primorial_ui.c for a complete example. + * Generic use is + * size = primesieve_size (end); + * sieve = __GMP_ALLOCATE_FUNC_LIMBS (size); + * primepi = gmp_primesieve (sieve, end); + * LOOP_ON_SIEVE_BEGIN (<name of prime variable>, + sieve_n_to_bit(<start>), sieve_n_to_bit (end), 0, sieve); + * <DO SOMETHING WITH <name of prime variable>> + * LOOP_ON_SIEVE_END; + * + * If the loop needs to be broken into different stages (up to sqrt(end), rest) + * LOOP_ON_SIEVE_CONTINUE and LOOP_ON_SIEVE_STOP can be used. + */ On Mon, Mar 16, 2020 at 3:29 AM Niels Möller <ni...@lysator.liu.se> wrote: > Seth Troisi <brain...@gmail.com> writes: > > > It's not clear where this should be documented, if someone tells me I'm > > happy to add some documentation. > > Since it's an internal interface, it doesn't need documentation in the > user manual. Documentation in comments in gmp-impl.h is fine, I think. > > Regards, > /Niels > > -- > Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677. > Internet email is subject to wholesale government surveillance. >
diff -r 251f1073f244 gmp-impl.h --- a/gmp-impl.h Sun Mar 15 23:01:22 2020 -0700 +++ b/gmp-impl.h Mon Mar 16 17:53:17 2020 -0700 @@ -2078,7 +2078,25 @@ __GMP_DECLSPEC mp_limb_t gmp_primesieve (mp_ptr, mp_limb_t); -/* primesieve macros and functions */ +/* + * primesieve macros and functions + * + * These macros are used to iterate over primes found by gmp_primesieve + * which are stored in a compact bit format (excluding multiples of 2 and 3). + * + * See mpz/primorial_ui.c for a complete example. + * Generic use is + * size = primesieve_size (end); + * sieve = __GMP_ALLOCATE_FUNC_LIMBS (size); + * primepi = gmp_primesieve (sieve, end); + * LOOP_ON_SIEVE_BEGIN (<name of prime variable>, + sieve_n_to_bit(<start>), sieve_n_to_bit (end), 0, sieve); + * <DO SOMETHING WITH <name of prime variable>> + * LOOP_ON_SIEVE_END; + * + * If the loop needs to be broken into different stages (up to sqrt(end), rest) + * LOOP_ON_SIEVE_CONTINUE and LOOP_ON_SIEVE_STOP can be used. + */ static mp_limb_t sieve_bit_to_n (mp_limb_t bit) { return (bit*3+4)|1; }
_______________________________________________ gmp-devel mailing list gmp-devel@gmplib.org https://gmplib.org/mailman/listinfo/gmp-devel