#35518 - ymalik - Sun Feb 06, 2005 12:40 am
Hello,
I need help on fixed point math. I don't know if this belongs here, and I couldn't find another topic regarding this. The fixed-point number is in 18.14 format.
I have the following program:
But it outputs the following:
floating point: -130.123398
fixed point: -2131941
int part: -131
frac part: 14363
And I notice that the integer part is always one more than the original integer part, and the fractional part is always messed up.
Thanks,
Yasir
I need help on fixed point math. I don't know if this belongs here, and I couldn't find another topic regarding this. The fixed-point number is in 18.14 format.
I have the following program:
Code: |
#include <string.h> #define FIX_SCALEF 16384.0f #define FIX_FRAC_PART(n) ((n)&0x3fff) #define FIX_INT_PART(n) (n>>14) typedef int FIXED; int main() { float num = -130.1234; FIXED fixed = num*FIX_SCALEF; int int_part, frac_part; frac_part = FIX_FRAC_PART(fixed); int_part = FIX_INT_PART(fixed); printf("floating point: %f\n", num); printf("fixed point: %i\n", fixed); printf("int part: %i\n", int_part); printf("frac part: %i\n", frac_part); return 0; } |
But it outputs the following:
floating point: -130.123398
fixed point: -2131941
int part: -131
frac part: 14363
And I notice that the integer part is always one more than the original integer part, and the fractional part is always messed up.
Thanks,
Yasir