View Single Post
Old 2009-09-30, 23:57   #1
grandpascorpion
 
grandpascorpion's Avatar
 
Jan 2005
Transdniestr

503 Posts
Default Using long long's in Mingw with 32-bit Windows XP

Hi,

I'm using Mingw version 5.1.6 within Windows XP (32-bit).

I'd like to use 64-bit integers within C code but I'm running into problems.

unsigned long z = 2*3*4*5*6*7*8*9*10*11*12;
long long unsigned int zz = z*13*14;
printf("Here is zz: %I64u\n";

After checking on-line, I found that the correct format to use is (the Microsoft-specific) %I64u, but this prints the lower 32 bits only. (Note: making z a "long long unsigned int" doesn't change the output)

==============================================

I found a different problem doing simple arithmetic:

unsigned long z = 2*3*4*5*6*7*8*9*10*11*12;
long long unsigned int zz = z*13*14;
long long unsigned int b = 175*z;
long long unsigned int c = zz-b; // 7 * factorial(12)
printf("c is %I64u\n",c);

The correct answer is only: 3353011200 (< 2^32) but this code prints out an incorrect number (18446744072767595220) that is more greater than 2^32.
//////////////////////////////////////////////////////////

Any insight would be appreciated. Thanks.

(The background is that I have some gmplib code that I wrote which I want to speed up, if possible. I think I could do so by replacing some of the "big ints" with long longs.)
grandpascorpion is offline   Reply With Quote