Quote:
Originally Posted by JBotAlan
You aren't *supposed* to use floats, because the processor doesn't natively do floating point calculations, but the compiler spits out code that works.
|
The problem here is that on a processor that supports floating-point math, doing any floating-point arithmetic takes a single assembly operation. On processors that don't support it (like the RC processor), it has to be done in software. So, each time you do anything with a floating point number, the compiler will end up generating a LOT of code to do it (something like 100 lines of assembly instead of just one). This uses up a lot of extra code space and is obviously a lot slower.
The answer has already been provided here. If you need 1/10 accuracy, just multiply all of your numbers by 10. Also, if you're trying to multiply something by a fraction, but the result only needs to be an integer, keep this trick in mind. If you're multiplying by a fraction, you can multiply by the numerator first and then divide by the denominator afterwards to avoid floating point (just be careful of overflows). So when someone here was talking about multiplying by 180/127, do this instead:
(x * 180) / 127