Which works great if your system happens to consist of power-of-2 set of discrete angles. Congrats, you found the one case where defined signed overflow is a win.
I mentioned crypto. More generally big number arithmetic, which on current hardware requires representing numbers with several limbs. Defining some behaviours there comes in handy.
And again, checking for overflow after the fact, for instance to propagate a carry flag. Even if it's just a convenience, you have to admit this is one C/C++ deny us, for no good reason at all.
Optimizations are not a good reason: if the programmer cares so much about performance, the programmer will find the bottleneck and fix it. (And if the programmer is faced with a uniformly slow program, this is probably because the memory layout is out of whack, and no compiler is going to fix that —go data oriented instead of the usual dynamically allocated OO pointer soup.)
Portability is not a good reason: the affected platforms are very rare, and the standard could always say "implementation defined on platforms that support it, undefined otherwise".
It's not just signed overflow. There are just too many UB for any of us to remember, this is a fucking minefield. I'm not arguing for safety, but a little less surprises would be nice.
2
u/loup-vaillant May 31 '17
I don't recall ever talking about arithmetically meaningless behaviour. Wrapping around signed integers is plain old modular arithmetic.