Boost C++ Libraries: Ticket #12157: Dividing zero by zero produces one in boost::multiprecision::cpp_dec_float https://svn.boost.org/trac10/ticket/12157 <p> When using Boost multiprecision, dividing 0/0 produces 1. I would expected the result to be inf. When dividing other numbers by zero it does produce inf. </p> <pre class="wiki">#include&lt;iostream&gt; #include&lt;boost/multiprecision/cpp_dec_float.hpp&gt; typedef boost::multiprecision::number&lt;boost::multiprecision::cpp_dec_float&lt;0&gt;&gt; BigFloat; int main() { BigFloat zero(0); BigFloat one(1); std::cout &lt;&lt; zero / zero &lt;&lt; std::endl; std::cout &lt;&lt; one / zero &lt;&lt; std::endl; } </pre><p> I looked at operator/ from here: <a href="http://www.boost.org/doc/libs/1_60_0/boost/multiprecision/cpp_dec_float.hpp">http://www.boost.org/doc/libs/1_60_0/boost/multiprecision/cpp_dec_float.hpp</a> I think adding the case "if(iszero() &amp;&amp; v.iszero())" as below could solve this issue. </p> <pre class="wiki">template &lt;unsigned Digits10, class ExponentType, class Allocator&gt; cpp_dec_float&lt;Digits10, ExponentType, Allocator&gt;&amp; cpp_dec_float&lt;Digits10, ExponentType, Allocator&gt;::operator/=(const cpp_dec_float&lt;Digits10, ExponentType, Allocator&gt;&amp; v) { if(iszero() &amp;&amp; v.iszero()) { *this = inf(); return *this; } const bool u_and_v_are_finite_and_identical = ( (isfinite)() &amp;&amp; (fpclass == v.fpclass) &amp;&amp; (exp == v.exp) &amp;&amp; (cmp_data(v.data) == static_cast&lt;boost::int32_t&gt;(0))); if(u_and_v_are_finite_and_identical) { if(neg != v.neg) { *this = one(); negate(); } else *this = one(); return *this; } else { if(iszero()) { if((v.isnan)() || v.iszero()) { return *this = v; } return *this; } cpp_dec_float t(v); t.calculate_inv(); return operator*=(t); } } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12157 Trac 1.4.3 anonymous Tue, 26 Apr 2016 17:15:21 GMT <link>https://svn.boost.org/trac10/ticket/12157#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12157#comment:1</guid> <description> <p> It should be a NaN: 0/0 is undefined. </p> <p> I'll look into it. </p> </description> <category>Ticket</category> </item> <item> <author>vfaion@…</author> <pubDate>Tue, 26 Apr 2016 17:26:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12157#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12157#comment:2</guid> <description> <p> Oh I see, well in the case above, maybe just *this = nan() then. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 03 May 2016 11:34:03 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/12157#comment:3 https://svn.boost.org/trac10/ticket/12157#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.62.0</span> </li> </ul> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/d619a8e3db9ed59fc139c7170fe640f70fc0bc81"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/d619a8e3db9ed59fc139c7170fe640f70fc0bc81</a>. </p> <p> Thanks for the report! </p> Ticket