定点算法的浮点转换
我有一个使用 24 位定点计算的应用程序。我将其移植到支持浮点的硬件,因此为了速度优化,我需要将所有基于定点的计算转换为基于浮点的计算。
对于此代码片段,它正在计算尾数
for(i=0;i<8207;i++)
{
// Do n^8/7 calculation and store
// it in mantissa and exponent, scaled to
// fixed point precision.
}
因此,自此计算以来,确实将整数转换为尾数并将指数缩放为定点精度(23 位)。当我尝试将其转换为浮点数时,通过将尾数部分除以精度位并用精度位减去指数部分,它确实如此。 不工作。 请帮助提出更好的方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需计算一个转换系数并乘以它即可。在定点系统中什么值代表 1.0?乘以 1.0/那个即可得到转换结果。
定点一般是指整数部分固定位数,小数部分固定位数。根据你的描述,我猜测你有 1 位整数和 23 位小数;因此 1.0 的表示是 0x80000。转换系数为 1.0/0x80000。
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.
如果你的定点数有 23 位小数,
If your fixed point numbers have 23 bits of fraction,