4 ms·
Yeah, this is undefined behaviour and should not be expected to work, 100% agreed. Wouldn't it be faster to remove that costly ternary conditional operator by
by Kenji 11y ago
Yeah, this is undefined behaviour and should not be expected to work, 100% agreed.
Wouldn't it be faster to remove that costly ternary conditional operator by zeroing out the first bit? Well, there's one degenerate case, for minvalue of int, but that is degenerate either way.
- adwn 11y ago> Wouldn't it be faster to remove that costly ternary conditional operator by zeroing out the first bit? No, that wouldn't work for two's-complement numbers [1], only for sign-magnitude numbers (like IEEE floating-point numbers). For example, the value -2 is stored as 11111110 (in an 8-bit signed integer); setting the most significant bit to 0 would result in 01111110, or 126 in decimal. [1] https://en.wikipedia.org/wiki/Two's_complement https://en.wikipedia.org/wiki/Two's_complement