C++ 中的无符号双精度?
为什么 C++ 不支持无符号双精度语法?
Why doesn't C++ support unsigned double syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
为什么 C++ 不支持无符号双精度语法?
Why doesn't C++ support unsigned double syntax?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
因为典型的浮点格式不支持无符号数。例如,请参阅此 IEEE 754 格式列表。
添加通用硬件不支持的数字格式只会让编译器编写者的生活变得困难,并且可能被认为不值得付出努力。
Because typical floating point formats don't support unsigned numbers. See, for instance, this list of IEEE 754 formats.
Adding a numerical format that isn't supported by common hardware just makes life difficult for compiler writers, and is probably not considered worth the effort.
C++ 不支持无符号浮点类型,因为大多数浮点硬件不支持无符号浮点类型。某些显卡确实可以使用无符号浮点,但它通常是内部的,对程序或用户来说并不真正可见。
C++ doesn't support unsigned floating point types because most floating point hardware doesn't support unsigned floating point types. Some graphics cards do work with unsigned floating point, but it's generally internal, not really visible to a program or user.
无符号整数获得了额外的精度,并且与有符号整数的按位语义略有不同。浮点型和双精度型总是为符号保留一点位(在大多数硬件上)并且没有按位语义,因此使用无符号实数类型没有真正的好处。
Unsigned integers gain an extra bit of precision and have slightly different bit-wise semantics to signed integers. Floats and doubles always reserve a bit for the sign (on most hardware) and have no bit-wise semantics, so there's no real benefit in having an unsigned real type.