开发者

Unsigned double in C++?

开发者 https://www.devze.com 2022-12-24 14:06 出处:网络
Why doesn\'t C++ support unsigned 开发者_高级运维double syntax?Because typical floating point formats don\'t support unsigned numbers. See, for instance, this list of IEEE 754 formats.

Why doesn't C++ support unsigned 开发者_高级运维double syntax?


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++ 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消