Here are some functions for translating between unsigned long long
and mpz_t
. Note that mpz2ull
will smash your stack if the number is too big to fit into an unsigned long long
:
unsigned long long mpz2ull(mpz_t z)
{
unsigned long long result = 0;
mpz_export(&result, 0, -1, sizeof result, 0, 0, z);
return result;
}
void ull2mpz(mpz_t z, unsigned long long ull)
{
mpz_import(z, 1, -1, sizeof ull, 0, 0, &ull);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…