Why are there so many floats in the Android API?

前端 未结 5 1025
梦谈多话
梦谈多话 2021-02-07 09:46

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 a

5条回答
  •  情深已故
    2021-02-07 10:36

    For metrics that don't need too many significant digits (such as screen offsets), it would be memory-inefficient to use doubles instead of floats. Maximizing efficiency with regards to memory consumption is vitally important on mobile devices, where pretty much every resource is at a premium. And, when dealing with objects such as Rects—that could potentially be allocated by the thousands—it is clearly crucial to cut down on excess bits.

    I'm sure there are other reasons too :-)

提交回复
热议问题