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.

Java中的默认浮点类型是double。如果您将类似2.5的常量硬编码到程序中,Java会自动将其设置为double。当您对可能从更高精度中受益的浮点数或整数执行操作时,类型将“提升”为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?

但是在Android API中,一切似乎都是从声音音量到矩形坐标的浮动。在大多数绘图中都使用了一种名为RectF的结构; F代表浮动。对于那些经常将推广双打重新投入(浮动)的程序员而言,这真的是一种痛苦。难道我们都不同意Java代码是如此混乱和冗长吗?

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?

通常数学协处理器和加速器在Java中更喜欢双重,因为它对应于一种内部类型。有没有关于Android的Dalvik VM出于某种原因更喜欢花车?或者所有的浮点数都是API设计变态的结果?

5 个解决方案

#1


8

Depending on the CPU there will be no Floating Point Unit (FPU). So it has to emulate the FPU in Software. this is faster for a Float than for a Double. Or if the Device has a FPU it will be probably also be faster with Floats.

根据CPU的不同,将没有浮点单元(FPU)。因此它必须在软件中模拟FPU。对于Float而言,这比Double更快。或者,如果设备具有FPU,则Floats可能也会更快。

更多相关文章

  1. 如何执行删除请求而不返回类型或回调?(改造)
  2. 如何将Java中的类型与反射进行比较
  3. “checkout as maven project from scm”中缺少scm类型
  4. Spring Hibernate:没有类型为org.hibernate.SessionFactory的匹配
  5. java返回值是list的时候获取list的参数类型
  6. 如何知道Object是否为String类型对象?
  7. 如何让BlockingQueue接受多种类型?
  8. 当只使用get()和set()方法时,用原始类型替换AtomicBoolean?
  9. Java中的数据类型

随机推荐

  1. linux时间与网络同步 // tomcat、redis、
  2. PostgreSQL操纵大对象(图片等)
  3. MySQL 插件CONNECTION_CONTROL和CONNECTI
  4. MySQL字符串相加函数如何运行?似曾相识还
  5. mysql行级锁测试
  6. SQLServer---查询过程中的数据类型转化
  7. MySql 存储过程插入年月日
  8. sqlserverdate时间转换给出不正确的结果?
  9. 使用T-SQL中另一个(非xml)列的值更新XML
  10. 查看 SQL Server 作业(job)运行结果状态