Fixed Point to Floating Point and Backwards

柔情痞子 提交于 2019-12-11 14:46:02

问题


Is converting Fixed Pt. (fixed n bit for fraction) to IEEE double safe ?

ie: does IEEE double format can represent all numbers a fixed point can represent ?

The test: a number goes to floating pt format then back to it's original fixed pt format.


回答1:


Assuming your fixed point numbers are stored as 32-bit integers, yes, IEEE double precision can represent any value representable in fixed point. This is because double has a 53-bit mantissa, your fixed point values only have 32 bits of precision, and the floating-point exponent for the fixed point value is bounded between -32 and 32 (depending on where you consider the binary-point to lie in your fixed point values) which is well within the representable range.




回答2:


It all depends on the size and format of your fixed point type. Fixed point to floating point is safe if your fixed type has few enough bits not to become inaccurate when converted to float. The other way round your fixed point type would have to be extremely long because a double can potentially represent a very large value (magnitude-wise) in a small amount of bits.



来源:https://stackoverflow.com/questions/2574487/fixed-point-to-floating-point-and-backwards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!