Float or Double?

前端 未结 8 1942
北海茫月
北海茫月 2020-12-29 20:36

Which is faster, double or float, when preforming arithimic (+-*/%), and is it worth just using float for memory reasons? Precision is not an issue much of an issue.

8条回答
  •  梦谈多话
    2020-12-29 21:32

    http://developer.android.com/training/articles/perf-tips.html#AvoidFloat

    Avoid Using Floating-Point

    As a rule of thumb, floating-point is about 2x slower than integer on Android-powered devices.

    In speed terms, there's no difference between float and double on the more modern hardware. Space-wise, double is 2x larger. As with desktop machines, assuming space isn't an issue, you should prefer double to float.

    Also, even for integers, some processors have hardware multiply but lack hardware divide. In such cases, integer division and modulus operations are performed in software—something to think about if you're designing a hash table or doing lots of math.

提交回复
热议问题