Why are there so many floats in the Android API?

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2010-03-19T06:56:41Z Indexed on 2010/03/19 7:01 UTC
Read the original article Hit count: 248

Filed under:
|
|

The default floating point type in Java is the double. If you hard code a constant like 2.5 into your program, Java makes it a double automatically. When you do an operation on floats or ints that could potentially benefit from more precision, the type is 'promoted' to a double.

But in the Android API, everything seems to be a float from sound volumes to rectangle coordinates. There's a structure called RectF used in most drawing; the F is for float. It's really a pain for programmers who are casting promoted doubles back to (float) pretty often. Don't we all agree that Java code is messy and verbose enough as it is?

Usually math coprocessors and accelerators prefer double in Java because it corresponds to one of the internal types. Is there something about Android's Dalvik VM that prefers floats for some reason? Or are all the floats just a result of perversion in API design?

© Stack Overflow or respective owner

Related posts about android

Related posts about dalvik