关于在 .Net 中转换浮点数据类型的细节?
如果我没记错的话,双精度数或浮点数分为 3 部分:符号位、指数和尾数。
当双精度数被移位时,这些位是移位变量的整个二进制还是仅移位尾数?
If I remember right, a double or float is broken into 3 parts: a sign bit, the exponent, and the mantissa.
When a double is shifted, do the bits shift the entire binary of the variable or does it just shift the mantissa?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法转换浮点类型 - 至少在 C# 中是这样。
另一方面,如果你要重复乘以或除以二,你会看到我之前提到的:在标准化数字的范围内,左移将使指数增加一,右移将使指数减少一。在非正规数中,指数固定为 0,因此尾数必须改变。
编辑:为了回答您的评论,如果指数为零且尾数非零,则值表示次正规/非正规数。有关 IEEE 754 的更多一般信息,请参阅此页面,我有一个.NET 二进制浮点 页面。
You can't shift floating point types - in C# at least.
On the other hand, if you were to multiply or divide by two repeatedly, you'd see what I mentioned before: within the range of normalized numbers, shifting left would increase the exponent by one and shifting right would decrease the exponent by one. Within denormal numbers, the exponent is fixed at 0, so the mantissa has to change.
EDIT: To answer your comment, a value represents a subnormal/denormal number if the exponent is zero and the mantissa is non-zero. See this page for more information on IEEE 754 in general, and I have a page on .NET binary floating point.
据我所知,移位运算符仅在.Net 中的整数上定义。
As far as I know, shift operators are only defined on Integers in .Net.