64-bit integer conversion support
Torbjorn Granlund
tg at swox.com
Fri Apr 27 21:07:45 CEST 2007
I am developing a bigint library, which will have GMP as one of it's
implementation. I'd like to provide functions for converting between 64-bit
integer (both signed and unsigned) and bigint. The problem is that GMP's
integer conversion functions do not seem to support 64-bit integers (that
is, when long type is not 64-bit).
True, since there was no 64-bit integer type until C99 came along.
I can do something similar to what mpz_get_si does, only use more limbs if
needed, but this approach depends on GMP internal representation, which I
don't quite like.
Also there are import/export functions, but as I understand they are for
different purpose - it's just binary serialization, not conversion to
natively supported type.
So, the question is - what are the available options if I want to achieve
maximum portability, and performance is not critical here?
I'd use mpz_getlimbn if I were you. A my_mpz_get_ull based on
mpz_getlimbn would be just a few lines of code, at least if you just
want to support this for a 32-bit and 64-bit ABI, and assume the numb
size is 32 or 64 bits.
--
Torbjörn
More information about the gmp-discuss
mailing list