Boost C++ Libraries: Ticket #10104: program aborts with log1p(-2.0Q) https://svn.boost.org/trac10/ticket/10104 <p> The math functions, e.g., log1p, for float128 do not handle parameters outside the normal domain. Thus sqrt(-2.0Q) produces a nan as does log1p(-2.0), but log1p(-2.0Q) crashes. (Similar remarks apply to hypot and probably other similarly defined functions.) </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;cmath&gt; #include &lt;boost/multiprecision/float128.hpp&gt; #include &lt;boost/math/special_functions/log1p.hpp&gt; int main() { double x = -2; boost::multiprecision::float128 y = -2; std::cout &lt;&lt; std::sqrt(x) &lt;&lt; "\n" &lt;&lt; std::log1p(x) &lt;&lt; "\n"; std::cout &lt;&lt; sqrt(y) &lt;&lt; "\n"; std::cout &lt;&lt; boost::math::log1p(y) &lt;&lt; "\n"; } </pre><p> produces </p> <pre class="wiki">-nan -nan -nan terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;std::domain_error&gt; &gt;' what(): Error in function boost::math::log1p&lt;N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE&gt;(N5boost14multiprecision6numberINS0_8backends16float128_backendELNS0_26expression_template_optionE0EEE): log1p(x) requires x &gt; -1, but got x = -2. Aborted (core dumped) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10104 Trac 1.4.3 John Maddock Sat, 07 Jun 2014 14:13:12 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10104#comment:1 https://svn.boost.org/trac10/ticket/10104#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">invalid</span> </li> </ul> <p> It doesn't crash, it throws an exception which you don't catch. This is documented behavior for boost::math::some_special_function and can be controlled via policies: <a href="http://www.boost.org/doc/libs/1_55_0/libs/math/doc/html/math_toolkit/pol_tutorial.html">http://www.boost.org/doc/libs/1_55_0/libs/math/doc/html/math_toolkit/pol_tutorial.html</a> </p> Ticket Charles Karney <charles@…> Sat, 07 Jun 2014 16:58:02 GMT <link>https://svn.boost.org/trac10/ticket/10104#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10104#comment:2</guid> <description> <p> OK. Sorry for not researching this enough. Minor quibbles remain: </p> <ol><li>log1p(-2.0Q) -&gt; inf and not nan </li><li>log1p(-1.0Q) -&gt; inf and not -inf </li></ol> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 09 Jun 2014 11:50:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10104#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10104#comment:3</guid> <description> <p> Not so minor, but I'm unable to reproduce (admittedly using current develop), this: </p> <pre class="wiki"> std::cout &lt;&lt; boost::math::log1p(float128(-1)) &lt;&lt; std::endl; std::cout &lt;&lt; boost::math::log1p(float128(-2)) &lt;&lt; std::endl; </pre><p> Outputs </p> <pre class="wiki">-inf nan </pre><p> as expected. </p> </description> <category>Ticket</category> </item> </channel> </rss>