A page on the Android developer's site mentions that you should (quote): "Avoid Using Floating-Point" (link: Performance Tips)
After reading the whole article, it seems that some of the items there may be a bit outdated (perhaps written a few years ago).
I would like to know whether this guideline is still valid today, or whether it is really bad (x2 performance hit, even on today's hardware) to use floating point types?
Older Android devices like ARMv6 had no processor support for floating point arithmetic. If you stick to using Java your usage of floats would be accomplished through emulation and although it would work on older devices, your software would be extremely slow and power hungry if you were using floats in your display loop or something similar that updates 20+ times per second.
ARMv7 and beyond have floating point arithmetic support so it isn't such a big deal even though fixed point or integer arithmetic would be preferred if you thought your software would also have to support older devices.
See related question for OpenGL/high performance Android applications: Floating point or fixed-point for Android NDK OpenGL apps?
IMHO, the statement to Avoid Using Floating-Point is ridiculous. If you need floating-point, you need floating-point. End of the line. You should not avoid it when you need it. Because, you will probably try to find ways around it with integers, but the calculations will be more complex and less clear for the programmer to read/debug code.
When you take a look at this gorgeous answer on SO, you will see that Floating Point Operations (FLOPS) are still really fast. FLOPS per cycle for sandy-bridge and haswell SSE2/AVX/AVX2. They speak about multiple FLOPS per cycle!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With