Is there a way to convert a mpz_t variable to unsigned long long in C?How about the other way around,from ull to mpz_t?The gmp library doesn't support this as ull are part of C99. I found this but it's in c++,and I don't know how to code in c++.Thanks in advance.
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
These functions should work to convert between mpz_t and signed/unsigned long long. They should be reasonably fast since they avoid having to do string processing:
The function signatures are supposed to look like native GMP functions. As with other
gmpz_set_
functions, these assume the variables passed have been initialised already, but it is easy to change them intogmp_init_set_
style functions.Here are some functions for translating between
unsigned long long
andmpz_t
. Note thatmpz2ull
will smash your stack if the number is too big to fit into anunsigned long long
: