Electronic – DIY FP – Implementing floating point math on a microcontroller without a hardware FPU

floating pointmicrocontroller

I'm working on a little personal project (targeting a Parallax Propeller, but this should be pretty generalizable) that needs floating point math.

The micro-controller I am working with does not have native floating point, or a stock floating-point library.

Are there any good resources or tutorials on implementing software floating-point math? Preferably on really limited resources (I don't even have a stack!).


I'd like to support double sized floats. The propeller is a 32 bit MCU, so I'll have to use multiple variables for each float.

I know there is one software-floating-point library for the propeller out there, but it only supports single sized floats.

No, I probably don't really need double sized floats, but this sounds like a really interesting project. Half the reason I want to do this is because I'll learn a lot along the way.

Best Answer

If you want to do it yourself, I'd say just do it.

I guess you wont find too many resources or tutorial because there is not much to it.

Here is an outline:

  • adding/subtracting:
    if exponents differ too much (more than the mantissa has bits):
    just return the value with larger exponent (if this is the subtrahend: negate)

    if exponents are similar:
    shift the mantissa of smaller value by difference of exponents and add to/subtract from other mantissa (using fixed point arithmetic)
    if result is not 0: shift mantissa up until MSBit of result is 1 and decrement exponent the same amount

  • multiplication/division:
    multiply/divide mantissas (using fixed point arithmetic) and add/subtract exponents