views:

211

answers:

2

Hi,

I have an application which is using 24 bit fixed point calculation.I am porting it to a hardware which does support floating point, so for speed optimization I need to convert all fixed point based calculation to floating point based calculation.

For this code snippet, It is calculating mantissa

for(i=0;i<8207;i++)
{
  // Do n^8/7 calculation and store 
  // it in mantissa and exponent, scaled to 
  // fixed point precision.

}

So since this calculation, does convert an integer to mantissa and exponent scaled to fixed point precision(23 bit). When I tried converting it to float, by dividing the mantissa part by precision bits and subtracting the exponent part by precision bit, it really does' t work. Please help suggesting a better way of doing it.

+1  A: 

Just calculate a conversion factor and multiply by it. What value represents 1.0 in your fixed point system? Multiply by 1.0/that and you'll have your conversion.

Fixed point generally refers to a fixed number of bits for the integer part, and a fixed number of bits for the fractional part. By your description, I'm going to guess that you have 1 bit of integer and 23 bits of fraction; therefore your representation of 1.0 is 0x80000. The conversion factor is 1.0/0x80000.

double conversionFactor = 1.0 / 0x80000;
floating = fixed * conversionFactor;
Mark Ransom
Thanks for the reply. Can you please elaborate it with a handy example as it will help a lot.
Viks
+1  A: 

If your fixed point numbers have 23 bits of fraction,

f = n * (1.0 / 0x800000)
Doug Currie
Should it be applicable for both mantissa and exponent. or only on mantissa. What should I do with exponent part.
Viks
Fixed point has no exponent part.
Doug Currie