For what purpose does java have a float primitive type?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-04-28T22:14:47Z Indexed on 2010/04/28 22:17 UTC
Read the original article Hit count: 233

Filed under:
|
|
|
|

I heard plenty times different claims about float type in java.

The most popular issues typicaly regard to converting float value to double and vice versa. I read (rather long time ago and not sure that it's actual now with new JVM) that float gives much worse performance then double. And it's also not recommended to use float in scientific applications which should have certain accuracy.

I also remember that when I worked with AWT and Swing I had some problems with using float or double (like using Point2D.Float or Point2D.Double).

So, I see only 2 advantages of float over double:

  1. it needs only 4 bytes while double needs 8 bytes

  2. JMM garantees that assignment operation is atomic with float variables while it's not atomic with double's.

Are there any other cases where float is better then double? Do you use float's in your applications?

It seems to me that the only valuable reason java has float is backward compatibility.

© Stack Overflow or respective owner

Related posts about java

Related posts about float