Why is numeric_limits <int> :: min () defined differently?
To get the smallest value, I have to use numeric_limits<int>::min()
I assume the smallest int is -2147483648, and tests on my machine showed this result. But some C ++ links, such as Open Group Base Specifications and cplusplus.com define it with a value of -2147483647.
I ask this question because in my implementation of the Framework NegaMax (search for the game tree) the minimum integer * (-1) must be defined correctly. Yes, with a minimum value of int = (numeric_limits :: min () + 2) In any case, I am safe, so my question is more theoretical, but I think it's still quite interesting.
If the value is represented as a sign and a value instead of two additions, the sign bit is equal to one with all other bits as zero, equal to -0. In sign and magnitude, the maximum positive integer and negative integer are the same magnitude. Two additions may represent another negative value, since it does not have the same symmetry.
From the cplusplus.com link you posted (highlighted by me):
The next panel shows the different constants and their guaranteed minimum values (positive numbers may be larger in value, and negative numbers may be less significant). Any particular compiler implementation can define integral types with larger values ββthan those shown here.
Numerical restrictions are always determined by the system and the compiler, try starting with a 64-bit compiler and the system, you can see completely different numbers.
C ++ uses two compliments for signed integers. Thus, the smallest signed integer is determined to be 100..00 (usually 32 bits).
A simple move 1<<(sizeof(int)*8-1) should give you the smallest signed integer.
Obviously, for unsigned integers, the smallest value is 0.
edit: you can read here
edit2: apparently C ++ doesn't necessarily use a compliment of two sides, my mistake