wood burning stoves
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 Building Microservices this week in the Design 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: 3718
    
  61

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
 
It's not a secret anymore!