<div dir="ltr"><div class="gmail_extra">As a point of information, the Intel Decimal Floating-Point Library (&lt;<a href="http://www.netlib.org/misc/intel/">http://www.netlib.org/misc/intel/</a>&gt;)<br>is utterly cavalier about its usage of signed integer arithmetic.  It overflows with abandon, and couldn&#39;t<br>be more clear that it expects 2&#39;s-complement arithmetic behavior.  Compiling with optimization turned<br>on breaks different parts of the code on different platforms, and fixing it always involves doing the same<br>thing that the code is already intending to do, but avoiding formally undefined behavior.<br><br>For example, the library contains this code snippet:<br><font face="monospace, monospace">    int x = ...;<br>    BID_UINT64 res;<br>    ...<br>    x = ~x + 1;<br>    res = (unsigned int) x | 0xb1c0000000000000ull;</font><br>and fails under optimization on some platforms when x is INT_MIN (presumably because ~INT_MIN<br>is INT_MAX and INT_MAX + 1 overflows).  Changing this to<br><font face="monospace, monospace">    res = (1u + (unsigned int) ~x) | </font><span style="color:rgb(34,34,34);font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><font face="monospace, monospace">0xb1c0000000000000ull;</font><br>made the optimized compiled code work.  The bit operations of the two versions of the code are the same.<br><br>Of course, you can blame the developers.  The library is dated 2011, so it&#39;s not like this is terribly old code.<br>But this library is perhaps the perfect example of code that needs to assemble objects at the bit level.<br>Needing to worry about things like left shifts of negative numbers, or overflow that isn&#39;t really, while trying<br>to put all the bits in their right places, is an extra useless burden.<br><br>Optimizationism is the bane of C and C++.<br><br></span></div></div>