Is the non-negative range of the signed C ++ number at least as large as the negative range?

Does the C ++ standard indicate that a non-negative range of a standard signed integer type is no less than a negative range?

EDIT: Note that I am referring to a non-negative range, not a positive range, which is obviously one less than non-negative .

EDIT: if we assume C ++ 11, the answer is "Yes." See My explanations below. From the point of view of C ++ 03, the answer is probably No.

The same question can be asked in the following way: if the standard guarantees results a - bin the standard ads integer type T, suggesting that both aand b negative values of the type T, and that a β‰₯ b?

I know that the standard allows two additions, additions and signed values ​​of negative values ​​(see C ++ 11 section 3.9.1 [basic.fundamental], clause 7), but I'm not sure it requires the use of one of these three representations. Probably not.

If we accept one of these three representations and assume that there are no β€œfalse” restrictions for either of the two ranges (negative and non-negative), then it is true that the non-negative range is at least as large as the negative. In fact, with two additions, the size of the two ranges will be equal, and with two other representations, the size of the non-negative range will be larger than the size of the negative.

However, even if we accept one of the above ideas, this is really not enough to guarantee anything about the size of any range.

I am looking here for a section (or set of sections) that uniquely provides the desired guarantee.

Any help would be appreciated.


, : " " :

  • ( / )
  • ( )

, C99 - . - - ?


, C99 ( TC3) 6.2.6.2 " ", 2:

: , . ; . , , , , ( M N , M ≀ N). , . , :

  • 0 ( );
  • - (2 N) ( );
  • - (2 N - 1) ( ).

, , 1 ( ) 1 ( ), . , , , .

- , C99 ++ 11?


C99, ++ 11, , C99 6.2.6.2 ++ 11.

C89/C90 , C99, , ++ 11.

, ++ 11 ( C99) :

  • ( + ) : , .

  • ( + ).

:

-1 ≀ min<T> + max<T> ≀ 0

T (standard + extended), min<T> max<T> std::numeric_limits<T>::min() std::numeric_limits<T>::max() .

, , a b ( ), , a - b decltype(a - b) a b , .

+4
1

, , , . , , 3.9.1/2:

: " char", " int", "int", "long int" "long long int". , .

3.9.1/7:

bool, char, char16_t, char32_t, wchar_t, .48 A - . .

. , .

+3

Source: https://habr.com/ru/post/1530278/


All Articles