Does the "Avoid using floating-point" rule of thumb apply to a microcontroller with a floating point unit (FPU)?

You should remember that the FPUs on these microcontrollers are often just single-precision FPUs. Single precision floating-point has only a 24 bit mantissa (with the hidden MSB) so you may get better precision from 32 bit integers in some cases.

I have done work with using fixed-point arithmetic, and for situations where the data has a limited dynamic range you can achieve the same precision as single-precision floating point using 32-bit fixed point with about an order of magnitude improvement in execution time. I have also seen that the compiler drags in a fair amount of library overhead for the FPU.


If you buy a processor with a hardware FPU, you don't have the same concerns about precision*, reentrant behaviour etc. Go ahead and use them!

Couple of thoughts though:

  • You might consider that the processor can power down the (large) FPU when it's not used, so check that running your FP routines saves you power (if you care about that) over doing it in software.

  • Depending on the implementation, the FPU might also have different registers to the core - sometimes compilers can make clever use of these.

  • Don't use the FPU as a crutch for bad firmware design. For example, could you do the same thing with fixed point, and use the normal core instead?

(* The FPU should conform to a given standard implementation, so be aware of any limitations arising from that.)


Some of the concerns still apply.

  • Floating-point arithmetic is inherently more computation-intensive than integer. But with a floting-point unit, you probably won't notice that any more, maybe a few additional cpu cycles or a bit more power consumption.
  • Operations are atomic, so that concern is gone.
  • the precision / rounding / comparison problem is still there, to exactly the same amount as in software computation.

Especially the latter one can cause very nasty problems, and force you to write non-intuitive code, e.g. always comparing against a range, never testing equality against a fixed value.

And remember that a single-precision float only has 23 bits resolution, so you might need to replace a 32-bit integer with a double-precision float.