https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24568
Tobias Schlüter <tobi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #11 from Tobias Schlüter <tobi at gcc dot gnu.org> --- Take milliDiff = INT_MIN (<0). milliDiff_6 = -milliDiff_5(D); // milliDiff_6 = INT_MIN (still <0) minutesDiff_13 = milliDiff_6 / 60000;// minutesDiff_13 = INT_MIN/60000 = -35791; minutesDiff_8 = -minutesDiff_13; // minutesDiff_8 = 35791 (>0!) So negation and division don't commute over the two's complement integers, and I don't think there is any bug left. I'm taking the liberty to close this. Link to a demonstration on the Compiler Explorer: https://godbolt.org/z/hnjcMdjnq Why the person who wrote that original bit of code wanted to deal with INT_MIN (LONG_MIN in the original, but the testcase would overflow if sizeof(int) < sizeof(long)) in this way is another question.