Because the negative side of the integer has more numbers than the positive one, about the only thing you can do to switch the sign safely is use a bigger type.
One notices that there are no problems with this example...
Code:#include <stdio.h> #include <stdint.h> #include <limits.h> int main(void) { printf("%lu\n", -(uint64_t)INT_MIN); return 0; }
Last edited by whiteflags; 12-26-2017 at 06:13 AM.
Last edited by john.c; 12-26-2017 at 11:23 AM.
A little inaccuracy saves tons of explanation. - H.H. Munro