mpz_mod inside loop

Richard Damon Richard at Damon-Family.org
Fri May 17 12:37:30 UTC 2019


On 5/17/19 8:17 AM, Torbjörn Granlund wrote:
> I suppressed one line which made my suggested shift-up solution hard to
> read.  Here is more complete code, with assignment of s:
>
>   unsigned long s = mpz_sizeinbase (a, 2);
>   mpz_mul_2exp (a, a, (GMP_NUMB_BITS - s) % GMP_NUMB_BITS);
>
> Of course, this is equivalent to (-s) % GMP_NUMB_BITS as GMP_NUMB_BITS
> divides GMP_NUMB_BITS...
>
Not quite. -1 % 64 = -1 not 63, as -1 / 64 == 0 so the remainder is
negative, and division is defined as truncation (towards zero) not
flooring (towards minus infinity)

-- 
Richard Damon



More information about the gmp-discuss mailing list