mpz_mod inside loop

Paul Underwood paulunderwood at mindless.com
Fri May 17 13:02:26 UTC 2019


> 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...
>

Thanks for the change to my post. However, I am now finding the greatest efficiency by using GMP_NUMB_BITS/2 not just GMP_NUMB_BITS:

  unsigned long S = mpz_sizeinbase (n, 2);
  mpz_mul_2exp (align, n, (GMP_NUMB_BITS/2 - S) % GMP_NUMB_BITS/2);

Best

Paul


More information about the gmp-discuss mailing list