C++ 中的无符号双精度数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2523025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:47:37  来源:igfitidea点击:

Unsigned double in C++?

c++doubleunsigned

提问by lost3den

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

为什么 C++ 不支持 unsigned double 语法?

回答by unwind

Because typical floating point formats don't support unsigned numbers. See, for instance, this list of IEEE 754 formats.

因为典型的浮点格式不支持无符号数。例如,请参阅此 IEEE 754 格式列表

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.

添加通用硬件不支持的数字格式只会让编译器编写者的生活变得困难,并且可能被认为不值得付出努力。

回答by Jerry Coffin

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.

C++ 不支持无符号浮点类型,因为大多数浮点硬件不支持无符号浮点类型。一些图形卡确实使用无符号浮点数,但它通常是内部的,对程序或用户并不真正可见。

回答by Marcelo Cantos

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.

无符号整数获得了额外的精度,并且与有符号整数的按位语义略有不同。浮点数和双精度数总是为符号保留一点(在大多数硬件上)并且没有按位语义,因此使用无符号实数类型没有真正的好处。