3 ms·
Ok, I think this should do the trick: return((a ^ b) | (a ^ (*rp)) < 0) ? 1 : 0; doesn't it?
by professorTuring 12y ago
Ok, I think this should do the trick:
return((a ^ b) | (a ^ (*rp)) < 0) ? 1 : 0;
doesn't it?
- pbsd 12y agoNot yet. Consider a = -1, b = 1. Due to the OR, any a and b with different signs will return overflow.
- professorTuring 12y agoOk this is my dumbest time in life xD (I just directly didn't take into consideration that part because it never has overflow...)...
- barrkel 12y agoMost people don't appreciate how complicated C's mix of signed and unsigned is, especially when undefined behaviour of signed overflow is included.
- professorTuring 12y agoDefinitely. Child, this is why I always add unit tests.