Forum Discussion
Altera_Forum
Honored Contributor
14 years agoMultiplication Rounding
Hey guys, I am multiplying two 32 bit numbers using LPM_MULT. Each number is in Q16.16 fixed point format. The product is a 64 bit Q32.32 number. I then shift the product to the ri...
Altera_Forum
Honored Contributor
14 years ago --- Quote Start --- Lets say you have Q2.2 notation. You have two numbers: 01.11=1.75 x 10.00=2.00 The product should be 3.50 If I do the binary multiplication in my calculator I get a Q4.4 result: 00111000 --- Quote End --- So far, soo good. --- Quote Start --- Now I perform the rounding by adding P(3) to P(7:4) I get: 0011+0001=0100 If I'm interpreting this correctly, it appears that my 3.5 rounded to a 4. But, there isn't any fractional part of the number. The rounding forced the result to Q4.0. Instead of getting 11.10=3.5, I got 0100=4. --- Quote End --- Your mistake is not in the rounding part, it's in the cutting part. You had a Q4.4 value and trimmed it's 4 LSBs. Thus, you got a Q4.0 value. Q4.0 can only represent 3 or 4, not 3.5. The rounding is actually correct for a conversion to Q4.0: it rounded 3.5 to 4.