Integers conversions

Torbjorn Granlund tg at gmplib.org
Tue Sep 27 11:39:07 CEST 2011


Zdenek Prikryl <iprikryl at fit.vutbr.cz> writes:

  Hi,
  the following situation is a little bit confusing. Let's assume
  following situation:
  
  mpz_t mp;
  mpz_init_set_ui(mp, 0xffffffffU);
  printf("s %x, u %x, s %s\n", mpz_get_ui(mp),
                               mpz_get_si(mp),
                               mpz_get_str(NULL, 16, mp));
  
  I'd expect that all print outs will be the same (i.e. 0xffffffff). But
  the real situation is different and the output is:
  
  s ffffffff, u 7fffffff, s ffffffff
  
  Why the mpz_get_si() returns wrong value? It should return -1 (0xffffffff)?

Please read the documentation for mpz_get_si.

-- 
Torbjörn


More information about the gmp-discuss mailing list