如何用二进制表示-0
本题涉及将小于abs(1)且为负数的浮点数转换为32.32格式,例如:-0.1234。
当其转换为 32.32 时,整数部分和小数部分分别分为高位和低位 32 位字。在上面的示例中,高 32 位将保存 -0,而低 32 位将保存 0.1234,两者均转换为二进制。
那么问题是,在这种情况下,如何正确地用二进制表示 -0 值?
This question concerns converting a floating point number that is less than abs(1) and negative to 32.32 format, for example: -0.1234.
When this is converted to 32.32, the integer portion and fractional portion are separated into the upper and lower 32 bit words, respectively. In this example above, the upper 32-bits will hold -0, while the lower will hold .1234, both converted to binary.
So the question is, in this case, how does one properly represent the -0 value in binary?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于。
It depends.
+0 == 0 == -0
用于实际编程目的。在这种情况下,您必须弄清楚底层系统如何处理负数。 (通常是二进制补码或符号位 )并相应地进行猴子操作。+0 == 0 == -0
for practical purposes of programming. In this case, you would have to figure out how negative numbers are being handled but the underlying system. ( Generally either two's complement or sign bit ) and monkey with that accordingly.