Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

32bit int * 32bit int = 64 bit int?

In other words does this work as expected?

int32 i = INT_MAX-1;
int64 j = i * i;

or do I need to cast the i to 64 bit first?

like image 666
Michael Avatar asked Apr 19 '09 11:04

Michael


1 Answers

You need to cast at least one of the operands to the multiply. At the point the multiply is being done, the system doesn't know you're planning to assign to an int64.

(Unless int64 is actually the native int type for your particular system, which seems unlikely)

like image 113
Will Dean Avatar answered Sep 28 '22 04:09

Will Dean