4 Byte limit on mpz_and (mpz_t ROP, mpz_t OP1, mpz_t OP2)

Douglas Davis davisdl48 at gmail.com
Fri Jul 19 15:21:49 CEST 2013


 Both

mpz_set_str(bmask,"0xffffffffffffffff",0);
mpz_and(k,k,bmask);

and

mpz_set_str(bmask,"0xffffffff",0);
mpz_and(k,k,bmask);

give the same results.  This indicates a 4 Byte limit on mpz_and() when ROP
and OP1 are the same mpz_t

Version information

OpenSUSE 12.3 packaged software.
gmp-devel-5.0.5-8.1.1.x86_64

> gcc --version
gcc (SUSE Linux) 4.7.2 20130108 [gcc-4_7-branch revision 195012]

> uname -a
Linux linux-1nh3.site 3.7.10-1.16-desktop #1 SMP PREEMPT Fri May 31
20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/Linux

-----------Code to reproduce problem--------

#include <gmp.h>
#include <stdio.h>

int main(int argc,char **argv) {
  mpz_t k,bmask,km;
  mpz_inits(k,km,bmask,NULL);

  printf("correct result pair\n");
  mpz_set_str(k,"12345678901234567890",10);
  mpz_set_str(bmask,"0xffffffffffffffff",0);
  printf("\nmpz_and(km,k,bmask); - 8 Byte \n");
  mpz_and(km,k,bmask);
  mpz_out_str (stdout,10, km);

  mpz_set_str(k,"12345678901234567890",10);
  mpz_set_str(bmask,"0xffffffff",0);
  printf("\n\nmpz_and(km,k,bmask); - 4 Byte \n");
  mpz_and(km,k,bmask);
  mpz_out_str (stdout,10, km);

  printf("\n\nincorrect result pairs\n");
  mpz_set_str(k,"12345678901234567890",10);
  mpz_set_str(bmask,"0xffffffffffffffff",0);
  printf("\n\nmpz_and(k,k,bmask); - 8 Byte \n");
  mpz_and(k,k,bmask);
  mpz_out_str (stdout,10, km);

  mpz_set_str(k,"12345678901234567890",10);
  mpz_set_str(bmask,"0xffffffff",0);
  printf("\n\nmpz_and(k,k,bmask); - 4 Byte \n");
  mpz_and(k,k,bmask);
  mpz_out_str (stdout,10, km);

  mpz_set_str(k,"12345678901234567890",10);
  mpz_set_ui(bmask,0xffffffffffffffff);
  printf("\n\nmpz_and(k,k,bmask); - 8 Byte ui \n");
  mpz_and(k,k,bmask);
  mpz_out_str (stdout,10, km);

  mpz_set_str(k,"12345678901234567890",10);
  mpz_set_ui(bmask,0xffffffff);
  printf("\n\nmpz_and(k,k,bmask); - 4 Byte  ui\n");
  mpz_and(k,k,bmask);
  mpz_out_str (stdout,10, km);


  mpz_clears(k,km,bmask,NULL);
}


More information about the gmp-bugs mailing list