定点到浮点以及向后
正在转换固定点。 (固定 n 位分数)到 IEEE 双安全?
即:IEEE 双精度格式是否可以表示定点可以表示的所有数字?
测试:数字变为浮动 pt 格式,然后返回到原始固定 pt 格式。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的定点数存储为 32 位整数,是的,IEEE 双精度可以表示任何可以用定点表示的值。这是因为 double 具有 53 位尾数,您的定点值只有 32 位精度,并且定点值的浮点指数介于 -32 和 32 之间(取决于您考虑二进制点的位置)位于您的定点值中),这完全在可表示的范围内。
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.
这完全取决于定点类型的大小和格式。如果固定类型的位数足够少,在转换为浮点数时不会变得不准确,则定点到浮点是安全的。相反,定点类型必须非常长,因为双精度数可能以少量位表示非常大的值(按大小)。
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.