Re: unsigned int multiply, x86-64

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When x and y are both unsigned int (x*y) is also an unsigned int.
(long int)(x*y) means first compute the unsigned in (x*y) then promote it to long int. To get the answer you want, you need to promote one of the arguments of the multiply before multiplying. I don't know whether the optimizer will figure out to do the 32 bit multiply you want and store the 64 bit result or whether it would do a 64 bit multiply.
Also, are you sure (long int) is 64 bit?  I thought it was just 32.

Bob Plantz wrote:

I wrote some C code to multiply two unsigned (32-bit) ints and store the
result in a 64-bit unsigned int.

int main(void)
{
  unsigned int x, y;
  unsigned long int z;

  printf("Enter two integers: ");
  scanf("%u %u", &x, &y);

  z = (long int)(x * y);


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux