Need help with mpz_t...

David Cleaver wraithx at morpheus.net
Sun Jun 13 17:38:54 CEST 2010


Hello all,

I've run into some trouble trying to "load" mpz_t's with 64-bit int's.  I was 
wondering if someone here could show me what I'm doing wrong or suggest a better 
way to accomplish the following:

I have 2 64-bit numbers.  They are both an unsigned long long.  I am compiling 
on Windows with mingw64.  I am trying to just basically concatenate the 2 64-bit 
numbers into 1 128-bit mpz_t.

Here is what I am currently trying:
mpz_set_ui(my_result, 0);
mpz_add_ui(my_result, my_result, (u32_t)((results2[i]>>32)&0xffffffff));
mpz_mul_2exp(my_result, my_result, 32);
mpz_add_ui(my_result, my_result, (u32_t)(results2[i]&0xffffffff));
mpz_mul_2exp(my_result, my_result, 32);
mpz_add_ui(my_result, my_result, (u32_t)((results1[i]>>32)&0xffffffff));
mpz_mul_2exp(my_result, my_result, 32);
mpz_add_ui(my_result, my_result, (u32_t)(results1[i]&0xffffffff));

(I've typedef'd u32_t to be unsigned int)

It seems the bottom 32-bits from both inputs are correct in the output.  But the 
top 32-bits are 'not-always' correct in the output.  Here are a few examples of 
what the code above is producing for me:

00000000000100000000000010000020 (top number is 2 ULL next to each other)
00002000000100000000000010000020 (bottom number is mpz_t from above code)

00000000000000000000000000000000
00020000000000000400000000000000

00000000000000000000000000400000
00000000000000000000004000400000

00000000000204000000000084000000
000000000002040000c0000084000000

00000000000000000000000000000000
10010000000000008000000100000000

00000000000000000000000000001400
00000000000000000200002800001400

00000000002228000000000000404001
0014040d002228008400500800404001

00000000000000000000000000000000
00000000000000000000000000000000

00000000000000000000000000000000
00000000000000000000000000000000

00000000842038100000000080800024
82a14440842038100400010280800024

00000000000000000000000000000000
00000000000000000000000000000000

00000000400000000000000000000102
00002000400000000200000200000102

00000000000000000000000000080000
00000000000000000000000000080000

00000000080840110000000021100088
80088040080840111000020021100088

Thank you for your time.  Any help would be greatly appreciated.

-David C.


More information about the gmp-discuss mailing list