So, did anyone actually checked how exactly slow floating operations are?
Look at it this way. In
fixed point:
addition is one cycle
subtraction is one cycle
multiplication can be ~3 or 4 cycles
division is costly (but cheaper than floating point).
In floating point the
branch to the floating point emulator will cost you
more than the first three of the above (and that's not including the setup to the branch which will add at least another 3 or 4 cycles).
Just look at the representations, and you'll start to see why floating point in software is "messy". For fixed point you essentially just have:
1 bit sign
x bits integer
(31-x) bits precision
.. and you treat them as
integers for addition, subtraction, and comparison.
For floating point, you have:
1 bit sign
an x bit signed exponent (usually 8 bits)
(31-x) bits precision
... but they
can't be compared or treated as integers without normalisation. Then you've got special cases for zero, etc, etc, and it all turns into a ghastly mess.
2. What is better - translate for example 4 floating variables to fixed, multiply them altogether, then translate them back or simply multiply them using floating multiplication?
Mixing fixed and floating point is as bad (or worse) then using only floating point for speed.
As Peter said, if you know the range of the variables, fixed point is "easy" - in C you can even just wrap things in macros.
Debugging is also easy - divide by the 2^n value you set your fixed point at to get a floating point number.
E.g. in binary - "11111111.1" = 511 and there's one bit of precision so we divide by 2^1=2 = 511/2=255.5
Oh and as for division, a computer science teacher once said: he who does lots of division ... is an idiot.
