4 ms·
In some programs I like to have something like this to catch potential bugs: int abs_s(int x) { assert(x != INT_MIN); return (x >= 0) ? x :
by hornetblack 12y ago
In some programs I like to have something like this to catch potential bugs:
int abs_s(int x) {
assert(x != INT_MIN);
return (x >= 0) ? x : -x;
}
- ygra 12y agoThis assumes two's complement, though. With one's complement even `INT_MIN` would be fine to negate ;) (On that note: Are there even machines left to write code for that don't use two's complement? Or 8 bits per byte?)
- nitrogen 12y agoIt has been mentioned on HN before that there are DSPs that use the same size for byte, short, and int, and that size is not 8 bits.