简体   繁体   中英

Fixed point optimum algorithm for different decimal points

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".

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM