various fixes for clang
also fix a comment typo
This commit is contained in:
11
stb_divide.h
11
stb_divide.h
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user