You are not logged in.
I have following code
int64_t t1 = 999999999989999LL;
int temp = 10000;
int64_t t2 = (t1 * temp);
cout << "t2 = " << t2 << endl;
Result of this multiplication comes out to be negative. I am running on redhat linux 5, gcc 4.1.1.
Result t2 = -8446744073809561616
can you please tell me solution for this problem.
Thanks in advance for your help
Problem? You're exceding the scope of a signed 64-bit int and overflowing into the sign bit... This is normal, expected behavior...
I'm not sure what you're trying to accomplish, exactly... But, why not use an unsigned variable instead? ("uint64_t", or "unsigned long long"... And, use "ULL" as the literal suffix...) That will suffice for this narrow case you're dealing with now, at least... But, bump it up much more than that, and you'll end up overflowing the unsigned 64-bit int, as well... You're just getting to the limits of values you can deal with as native ints, so if you really need to deal with such huge values that won't fit in a 64-bit int, then you're going to have to move on to something like a bignum library instead of native ints...