1
votes

So I have a 32 bit processor I can program to in C that needs to be used with fixed point for speed.

I understand fixed point representation and basic implementation. What Im looking for is how to combine numbers with different number of decimal bits.

Lets say I sum Q10 + Q10 I would use Q10 as the sum. What If I sum Q10 and Q20? Is the an algorithm that takes into account both numbers and chooses the appropriate Qx value to minimize precision loss and overflows? I basically need addition, subtraction, multiplication and division.

The issue is that my operations may look like:

2*3.14159*50*1e-4*10 + 5.2*10

And I would rather avoid doing scaling and tricks "by hand".

1
How are you representing Q10? - grek40
If you are using fixed-point representations with variable scale, then scaling by hand is exactly what you've signed up for. Even with invariant scale, you probably still need to do some hand-scaling for multiplicative operations. You can wrap that in a function, of course, but that probably loses any performance advantage afforded by fixed-point in the first place. Depending on exactly what you need, perhaps a macro would be an appropriate vehicle to avoid code duplication. - John Bollinger
decimal bits is an oxymoron. - Eugene Sh.

1 Answers

0
votes

There is nothing readily available for the general purpose processors, but there is a project that claims having variable precision fixed point: https://versaweb.dl.sourceforge.net/project/fixedptc/fixedptc.h.

For PIC micro there are some libraries that deal with 8-bit size different Q arithmetic as described here: http://ww1.microchip.com/downloads/en/AppNotes/00617.pdf Also, you may see this for more generic description of the problem. http://www.superkits.net/whitepapers/Fixed%20Point%20Representation%20&%20Fractional%20Math.pdf Is there a need to write such a library it could be written if needed, with some effort.