Fixed point arithmetic

I am currently using the Microchip Fixed Point Library, but I think this applies to most fixed point libraries. It supports types Q15 and Q15.16, respectively 16-bit and 32-bit data.

One thing that I noticed is that it does not include the functions of adding, subtracting, multiplying or splitting.

How am I supposed to do this? Is it as simple as adding / subtracting / multiplying / separating them together using integer math? I see that addition and subtraction work, but multiplication or division will not take care of the fractional part ...?

+3
source share
2 answers

, - , . divide / *, 32- .

0

Microsoft , / (_Q15add _Q15sub).

( , - ).

C:

extern _Q15 Q15mpy(_Q15 a, _Q15 b);

( .s ):

.global _Q15mpy
_Q15mpy:
mul.ss w0, w1, w2        ; signed multiple parameters, result in w2:w3
SL w2, w2            ; place most significant bit of W2 in carry
RLC w3, w0           ; rotate left carry into w3; result in W0
return                        ; return value in W0

.end

libq.h

, 15 . , Q15 & ​​lt; = 1.

+1

Source: https://habr.com/ru/post/1778545/


All Articles