Unsigned double in C++?

≡放荡痞女 提交于 2019-12-03 05:23:38

问题


Why doesn't C++ support unsigned double syntax?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/2523025/unsigned-double-in-c

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