I am using MPIR 2.4.0 on Windows (MSVC 2010) and I was trying to add an unsigned 64bit integer to a mpz_t number. However it seems that MPIR/GMP does not support direct conversion between 64bit Integers and mpz_t. Does this mean I have to convert my uint64 to a string and read this via mpz_init_set_str? Neither is this very appealing nor does it look very quick - two conversion for nothing.
Did I miss something or what is the trick/hack to use here?
Cheers,
Philipp
As suggested by Banthar use mpz_import, but I'd suggest the following which does not rely on the platform endianness:
mpz_import(b, 1, 1, sizeof(a), 0, 0, &a);
Use mpz_import:
void mpz_set_ull( mpz_t rop, unsigned long long op )
{
mpz_import(rop, 1, 1, sizeof(op), 0, 0, &op);
}
EDIT: Code updated according to Frank's comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With