floating point - How is this in Q10 format? -
i've read else's code , claimed answer in q10 format. can't figure out how in q10. here code:
// convert x , y in such manner ratio of x y // produce value in q10 format cnt = 0; bitmask = 0x80000000; while((cnt < 10) && !(bitmask & x)) { x <<= 1; cnt++; } y >>= (10 - cnt); // calculate slope if (0 == x) slope = 0xffffffff; else slope = ((uint32)x)/(uint32)y;
any appreciated
i'll assume q10 mean value has 10 bits representing fractional portion of fixed point value. code in question produce q10 value if x
, y
inputs have same number of fractional bits (i.e., same "q" value). input x
shifted left 10 bits, increases q value of x
number of bits shifted. if x
shifted less 10 bits (to avoid overflow) y
shifted right remaining bits (decreasing q value of y
) difference between q values of x
, y
10. slope
calculated x/y
. when divide fixed point values q value of result equal q value of numerator minus q value of denominator. slope
q10 because q value of x
, y
differ 10.
Comments
Post a Comment