On Wednesday, 7 September 2016 at 14:46:46 UTC, Sai wrote:
I suspected the same, most of the CPUs support fast floating point operations anyway (with FPUs), shouldn't take a lot more time than doing integer arithmetic. Unless we are targeting 8bit avr or something similar.


No. Floating point in binaries are represented as
v = m * 2 ^ e

Now:

v0 / v1 = (m0 * 2 ^ e0) / (m1 * 2 ^ e1)
v0 / v1 = (m0 / m1) * 2 ^ (e0 - e1)

ie to do a 32 bits float division, you need to do a 24 bits integer division, while when doing a 32bits integer division you need to do a 32bits integer division (!)

The same apply to floating point multiply that are usually faster than integer multiply. In fact, on some machines, multiplying floats is faster than adding them.

Reply via email to