This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 3610
    
  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