This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes data type of results of java arithmetic calculation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "data type of results of java arithmetic calculation" Watch "data type of results of java arithmetic calculation" New topic
Author

data type of results of java arithmetic calculation

Ziyang Zhang
Ranch Hand

Joined: Jul 17, 2010
Posts: 47
In java, I know the data type of the result of an arithmetic calculation depends on the data types of the numbers involved in the calculation. For example,

int + int = int

long/double=double

a. But I can't find any references which can give me all these rules. Could someone help me?

b. How to avoid over flow in arithmetic calculation? For example, the results of 2 long may not fit into a long anymore...

Thanks a lot.


Enjoy life!
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

The JLS is the most authoritative source on the issue of type conversions in Java.

Java itself does not check integer arithmetic overflows, but I've found this interesting tool which does so.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: data type of results of java arithmetic calculation
 
Similar Threads
Tricky question.... plz help
date type "Long" range too small?
does == count as arithmetic calculation?
why ceil & floor accepts int
Not Getting Compilation Error?