Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Detect Overflow and Underflow

843811Sep 10 2004 — edited Sep 12 2004
Hi all,

How can i delect the overflow or underflow of a int&double value in following example code.

int i = Integer.MAX_VALUE; //Which is 2147483647

int k = i+1; //which is "-2147483648"

int l=Integer.MIN_VALUE; //which is -2147483648

int m = l-1; //which is 2147483647

As you can see the calculation is wrong, how can i catch this event in my code? Which is very important in my program.

Thank you!
Gene Tam
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2004
Added on Sep 10 2004
4 comments
335 views