N位有符号整数的最大保证范围是多少?

What is maximum guaranteed range of N-bit signed integer?

一些背景:

我试图找到 N 位有符号整数的最大范围的引号,但找到了 none。

所以我想知道(就 C++ 而言):

  1. 假设 N 位有符号整数的最大可能范围限制在 -2^(N-1)+2^(N-1) 之间是否正确?能再宽一点吗?
  2. 它是否会受到底层平台位实现的影响——比如“三态位”或类似的东西?

目前没有最终的 C++20 标准。您可能想到的 提案 是 P1236,上面写着:

The range of representable values for a signed integer type is -2^(N-1) to 2^(N-1)-1 (inclusive), where N is called the range exponent of the type.

这是最大值和最小值。因为该提案要求对有符号整数进行二进制补码,所以没有变化的机会。平凡地,N 位不能用于表示超过 2^N 个不同的值(根据鸽巢原理),因此范围尽可能大,即使它仅被指定为最小范围。

至于 three-state 位,那些不适用于该语言。

C++2a 虽然预计会成为 C++20 标准,但目前还没有。

除此之外,虽然当前草案对有符号整数实施 two's-complement representation,但当前标准 (C++17) 和所有前身确实 限制选择 :
具体来说,提供的其他选项是 signed magnitude representation and ones' complement。两者都具有 负零.

有关于 N-bit 有符号整数范围的信息。具体来说,并非 object-representation 的所有 N1 位都需要成为 [=32 的 N2 位的一部分=],the exception of the narrow character types. So, the value-representation's N-bit width might be smaller. Considering the pigeonhole-principle,不能再大也就不足为奇了。

比特是二进制的假设深深植根于语言中,就像它遍及许多其他 programming-languages 一样。改变这将是一个重大项目。