The Artima Developer Community
Sponsored Link

Java Answers Forum
detecting overflow and carry of ints in java

2 replies on 1 page. Most recent reply: Nov 12, 2003 11:51 PM by Tanya

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Tanya

Posts: 16
Nickname: seabeck
Registered: Nov, 2003

detecting overflow and carry of ints in java Posted: Nov 4, 2003 11:58 PM
Reply to this message Reply
Advertisement
Since java quietly allows overflow and carry. Is there another way to check the answer of a mathmatical operation for overflow besides checking for the max and min values of ints?

How about carry, the only way I can see is to hold the first bit of both ints in temp variables then doing the mathmatical operation and placing the answers first bit in a temp variable and doing several if statements to check if a carry occurred. However, this seems redundant! I realize an overflow will not occur if the first bit of both numbers are of opposite sign, so I guess I could check that first but it seems like that would waste execution time! Thanks, for any advice.


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: detecting overflow and carry of ints in java Posted: Nov 5, 2003 7:05 PM
Reply to this message Reply
Did this post

http://www.artima.com/forums/flat.jsp?forum=1&thread=19877

solve your problem or you solved it in a different way? If it is different please post the solution you used.

Tanya

Posts: 16
Nickname: seabeck
Registered: Nov, 2003

Re: detecting overflow and carry of ints in java Posted: Nov 12, 2003 11:51 PM
Reply to this message Reply
Sorry it took me so long to reply! I updated my other question and also answered the question you posted here.

http://www.artima.com/forums/flat.jsp?forum=1&thread=19877

Flat View: This topic has 2 replies on 1 page
Topic: Immutable String help Previous Topic   Next Topic Topic: Transactions in MDB

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use