direct conversion from int64_t
Marc Glisse
marc.glisse at normalesup.org
Tue Mar 10 22:14:08 CET 2009
On Tue, 10 Mar 2009, Atze Dijkstra wrote:
> I'd like to convert a int64_t directly to an mpz. As far as I can tell
> function 'mpz_set_si' is the most direct way to do this, but the 'signed long
> int' parameter turns out to be 32 bits only (MacOSX 10.5.6). Is there any way
> to directly convert a 64 bits value without splitting a 64 bits value into a
> most + least significant part, building separates mpz for these parts and
> shifting + multiplying these (or do 2 to+from string conversions...)? Am I
> overlooking alternatives to mpz_set_si, or is conversion from/to 64 bits
> values not supported on 32 bit platforms?.
Does mpz_import (big hammer) work for you?
There is regularly talk about adding support for long long, but I have no
idea how far away that may be.
(there are also ways to do this by hand, but it would be preferable to
stick to the official API so it does not break with the next version of
gmp)
Note that even with your solution you don't need to create two mpz_t, you
can create one from the high 32 bits, shift it, and add_ui the low 32 bits
(still need to take care of the sign).
--
Marc Glisse
More information about the gmp-discuss
mailing list