File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes loss of precision error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "loss of precision error" Watch "loss of precision error" New topic

loss of precision error

Puneet N Vyas
Ranch Hand

Joined: Sep 20, 2007
Posts: 61
when we compile this it gives possible loss of precision which is obvious,but why this same code runs in other language c/c++,i run it on linux based gcc compiler,can any one tell why this happens

Ronald Schild
Ranch Hand

Joined: Jun 09, 2008
Posts: 117
It compiles in other languages because there are differences between java and say, c++.

However, with c=(c+i) you assign an integer to a char which is a downcast that you need to make explicit.

All numbers are implicitly widened to an int when used in a calculation. The result is also at least an int.

Java hobbyist.
I agree. Here's the link:
subject: loss of precision error
It's not a secret anymore!