various fixes for clang

also fix a comment typo
This commit is contained in:
Sean Barrett
2019-02-25 11:10:54 -08:00
parent 5715e6faaf
commit 5fe7fb52f2
5 changed files with 22 additions and 32 deletions

View File

@ -163,20 +163,21 @@ int stb_div_floor(int v1, int v2)
#ifdef C_INTEGER_DIVISION_FLOORS
return v1/v2;
#else
if (v1 >= 0 && v2 < 0)
if (v1 >= 0 && v2 < 0) {
if ((-v1)+v2+1 < 0) // check if increasing v1's magnitude overflows
return -stb__div(-v1+v2+1,v2); // nope, so just compute it
else
return -stb__div(-v1,v2) + ((-v1)%v2 ? -1 : 0);
if (v1 < 0 && v2 >= 0)
if (v1 != INT_MIN)
}
if (v1 < 0 && v2 >= 0) {
if (v1 != INT_MIN) {
if (v1-v2+1 < 0) // check if increasing v1's magnitude overflows
return -stb__div(v1-v2+1,-v2); // nope, so just compute it
else
return -stb__div(-v1,v2) + (stb__mod(v1,-v2) ? -1 : 0);
else // it must be possible to compute -(v1+v2) without overflowing
} else // it must be possible to compute -(v1+v2) without overflowing
return -stb__div(-(v1+v2),v2) + (stb__mod(-(v1+v2),v2) ? -2 : -1);
else
} else
return v1/v2; // same sign, so expect truncation
#endif
}