unsigned long long conversion

Jens Hillenbach jhillenbach at yahoo.com
Thu Apr 7 17:30:51 CEST 2005

Hi Keith, I converted mpz_class into unsigned long long and vice versa

unsigned long long mpz2ull (mpz_class n)
  stringstream str;
  str << n;
  unsigned long long ull;
  str >> ull;
  return ull;

mpz_class ull2mpz (unsigned long long ull)
  stringstream str;
  str << ull;
  return mpz_class (str.str());

If u nedd mpz_t for better performance than mpz_class u can 
convert mpz_t into mpz_class (resp the other way) after that.
Bye, Jens

--- keith.briggs at bt.com wrote:
> I need to assign mpz_t and mpq_t variables from unsigned long longs.
> Mpfr has functions (names with _uj) for doing this, but it seems that
> gmp does not.
> Should I use mpz_import for this, or is there a better way?
> Keith
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at swox.com
> https://gmplib.org/mailman/listinfo/gmp-discuss

Yahoo! Messenger 
Show us what our next emoticon should look like. Join the fun. 

More information about the gmp-discuss mailing list