Boost C++ Libraries: Ticket #12559: sqrt for cpp_int_backend behaves incorrect for small argument values https://svn.boost.org/trac10/ticket/12559 <p> The sqrt function for multiprecision integers does not work for small values. Using this code: </p> <pre class="wiki">checked_int128_t int1; for (int i = 10; i &gt;= 0; i--) { int1 = i; try { int1 = sqrt(int1); std::cout &lt;&lt; "sqrt(" &lt;&lt; i &lt;&lt; ") = " &lt;&lt; int1 &lt;&lt; std::endl; } catch (std::exception&amp; ex) { std::cout &lt;&lt; "sqrt(" &lt;&lt; i &lt;&lt; ") -&gt; " &lt;&lt; typeid(ex).name() &lt;&lt; ": " &lt;&lt; ex.what() &lt;&lt; std::endl; } } </pre><p> I get the following output: </p> <pre class="wiki">sqrt(10) = 3 sqrt(9) = 3 sqrt(8) = 2 sqrt(7) = 2 sqrt(6) = 2 sqrt(5) = 2 sqrt(4) = 2 sqrt(3) -&gt; class boost::exception_detail::clone_impl&lt;struct boost::exception_detail::error_info_injector&lt;class std::overflow_error&gt; &gt;: Unable to allocate sufficient storage for the value of the result: value overflows the maximum allowable magnitude. sqrt(2) -&gt; class boost::exception_detail::clone_impl&lt;struct boost::exception_detail::error_info_injector&lt;class std::overflow_error&gt; &gt;: Unable to allocate sufficient storage for the value of the result: value overflows the maximum allowable magnitude. sqrt(1) = 0 sqrt(0) = 0 </pre><p> While sqrt(3) and sqrt(2) are raising an exception, sqrt(1) gives a wrong result. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12559 Trac 1.4.3 John Maddock Sun, 06 Nov 2016 12:00:04 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12559#comment:1 https://svn.boost.org/trac10/ticket/12559#comment:1 <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> </ul> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/4538e88a91b47a72a3e136672d1a7389e9035fd8"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/4538e88a91b47a72a3e136672d1a7389e9035fd8</a> </p> <p> Thanks for the report! </p> Ticket