When writing a program, the result is always wrong. Check logic has not found any errors several times, but debug is helpless. An interesting phenomenon was found: ABS (int_max-(-1) returned value is-2147483648. So I read the code implementation of the ABS function.
1 Int_ Cdecl ABS (2IntNumber3 )4 {5Return(Number> =0? Number :-Number );6}
the design of the unsigned number and signed number range is also related to the results after overflow. The ABS function parameter is int, which is signed. int_max-(-1) is greater than the int expression range, and its unsigned value is 2147483648, then the unsigned value is converted to a signed int of-2147483648. For the statement number> = 0? Number:-number. We get-(-2147483648), that is, 2147483648. The Return Value Type of the ABS function is int, which is signed. The value of 2147483648 is converted to-2147483648.