Floating point conversion from Fixed point algorithm
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, d开发者_高级运维oes 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.
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;
If your fixed point numbers have 23 bits of fraction,
f = n * (1.0 / 0x800000)
精彩评论