Boost C++ Libraries: Ticket #13558: gcd(INT_MIN, INT_MIN) crashes https://svn.boost.org/trac10/ticket/13558 <p> The following produces a SIGFPE for me: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;climits&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/integer/common_factor_rt.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">integer</span><span class="o">::</span><span class="n">gcd</span><span class="p">(</span><span class="n">INT_MIN</span><span class="p">,</span> <span class="n">INT_MIN</span><span class="p">);</span> <span class="p">}</span> </pre></div></div><p> because it simplifies <code>gcd(INT_MIN, INT_MIN)</code> =&gt; <code>gcd(INT_MIN % INT_MIN, INT_MIN)</code> =&gt; <code>gcd(0, INT_MIN)</code> =&gt; <code>gcd(0, INT_MIN % 0)</code> =&gt; gcd(0, SIGFPE)`. </p> <p> I'm actually not sure what the right behavior is (the documented behavior is that the return is always positive, and, for example, <code>gcd(-2, -2)</code> returns 2, but obviously you can't do that here). </p> <p> Boost 1.63 returned <code>INT_MIN</code> in this case, which seems like the best answer. </p> <p> Responsible commit: <a class="ext-link" href="https://github.com/boostorg/integer/commit/beb68718640150f67fe5671bbbb7848d9e7170b8"><span class="icon">​</span>https://github.com/boostorg/integer/commit/beb68718640150f67fe5671bbbb7848d9e7170b8</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13558 Trac 1.4.3 Evan Driscoll <evaned@…> Wed, 02 May 2018 20:28:33 GMT component changed; cc, owner set https://svn.boost.org/trac10/ticket/13558#comment:1 https://svn.boost.org/trac10/ticket/13558#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">evaned@…</span> added </li> <li><strong>owner</strong> set to <span class="trac-author">Daryle Walker</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">integer</span> </li> </ul> Ticket