Unsigned double in C++?

C++DoubleUnsigned

C++ Problem Overview


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

C++ Solutions


Solution 1 - C++

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.

Solution 2 - 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.

Solution 3 - C++

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionlost3denView Question on Stackoverflow
Solution 1 - C++unwindView Answer on Stackoverflow
Solution 2 - C++Jerry CoffinView Answer on Stackoverflow
Solution 3 - C++Marcelo CantosView Answer on Stackoverflow