3 ms·
Some microcontrollers used to have saturating arithmetic, which is basically the only other behavior that makes any sense.
by qsort 5y ago
Some microcontrollers used to have saturating arithmetic, which is basically the only other behavior that makes any sense.
- MaxBarraclough 5y agoPerhaps I'm missing something obvious, but isn't that orthogonal to representation? You could implement saturating arithmetic for any representation scheme, no?
- tomsmeding 5y agoYou can only observe whether the representation is 2s-complement or not if you can see what wrapping does.
- MaxBarraclough 5y agoThat doesn't sound right. You can use the union trick in C (but not C++, strictly speaking) to read the bit-pattern of a signed integer as an unsigned integer, for example. [0] Overflow of signed integer types remains undefined behaviour in both C and C++. A compiler is free to make a promise like signed integer overflow is always handled with wrapping or signed integer overflow is always handled with saturation. (GCC has a flag, -fwrapv, to enable guaranteed wrapping. [1]) [0] https://stackoverflow.com/a/25664954/ https://stackoverflow.com/a/25664954/ [1] https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html