dcsimg
OVERFLOW WITH int TYPES
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   dan_cabrera
Posted On:   Thursday, May 10, 2001 09:05 PM

I AM NOT SURE ABOUT THE FOLLOWING

public static void main(String arg[]) {
byte T = 0;
int R = 0, a = 12345, b = 234567;

R = a * b / b;

T = 256 * 33333 / 33333;

}

Why if I have an overflow on T and not on R ?

* I was under the impression that on R. Because what happen first, is the multiplication and that temp result is higher that what an (int) can hold, such condition will create an overflow. But if that is true why is not happening the same with T???

Re: OVERFLOW WITH int TYPES

Posted By:   Michael_Wax  
Posted On:   Friday, May 11, 2001 07:39 AM

An int is 32 bits long. The result of your a*b calculation is larger than an int, so you get an overflow. The result of 256*33333 is smaller than an int (max value 2147483647), so you see no overflow.
About | Sitemap | Contact