Ints have limited ranges. Floats can be slow and memory hogs. Are there any alternatives?
Recently Colin Walls had an article on this site about floating point math. Once it was common for embedded engineers to scoff at floats; many have told me they have no place in this space. Thatís simply wrong. The very first embedded program I wrote in 1972 or so used an 8008 to control a near-infrared instrument. Even though we were limited to 4KB of EPROM (it was incredibly expensive then), all of the math had to be in floating point using a library written by one Cal Ohne. Amazingly, he crammed that into just 1KB of program memory. And that was on an 8 bitter with a ferociously-bad stack and very limited instruction set.
Today even MCUs sometimes have on-board floating point hardware. STís STM32F4 parts, for instance, have this feature and some are under four bucks in 1000 piece lots.
But most working in the microcontroller space donít have hardware floating point, so have to use a software solution, which is slow and consumes a lot of memory.
We use integers because they are fast and convenient. But the dynamic range is limited and fractional arithmetic impossible. Floats give us enormous ranges but suffer from performance. An alternative, well known to DSP developers, is fixed point math.
This story continues on EE Times' sister site, Embedded.