Boost C++ Libraries: Ticket #4445: boost:math::float_advance( 0.0, 2 ) stack overflows if denormal numbers are set to zero https://svn.boost.org/trac10/ticket/4445 <p> If denormal numbers are set to be zero on the processor (register MXCSR bit 6 set) then float_distance( 0.0, any number that is not 1 ) will enter invoke a function recurse which fails to exit and the program will crash with a stack overflow. </p> <p> Ultimately given the current code, this is because boost::math::sign( denormal number ) == 0 as opposed to the sign of the denormal number. </p> <p> However, behaviour of this function with denormal numbers really ought to be defined and documented. Possibly a test to see if denormal numbers are disabled needs to be done this case handled appropriately. </p> <p> Example code, built with optimisations enabled </p> <p> #include &lt;boost/math/special_functions/next.hpp&gt; </p> <p> #include &lt;ippcore.h&gt; </p> <p> int main() { </p> <blockquote> <p> double thisWillWork = boost::math::float_advance( 0.0, 2 ); ippSetDenormAreZeros(1); <em> or set MXCSR bit six directly double thisWillStackOverFlow = boost::math::float_advance( 0.0, 2 ); </em></p> </blockquote> <p> </p> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4445 Trac 1.4.3 John Maddock Thu, 12 Jul 2012 10:01:28 GMT owner changed https://svn.boost.org/trac10/ticket/4445#comment:1 https://svn.boost.org/trac10/ticket/4445#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Douglas Gregor</span> to <span class="trac-author">John Maddock</span> </li> </ul> Ticket John Maddock Tue, 17 Jul 2012 09:23:02 GMT <link>https://svn.boost.org/trac10/ticket/4445#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4445#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/79572" title="Tentative fix for issue #4445. Adds tests for next.hpp when using the ...">[79572]</a>) Tentative fix for issue <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4445" title="#4445: Bugs: boost:math::float_advance( 0.0, 2 ) stack overflows if denormal ... (closed: fixed)">#4445</a>. Adds tests for next.hpp when using the SSE2 instruction set in DAZ and FTZ modes. Note that FTZ mode is particularly pernicious as non-zeros can change to zeros at random points in program flow depending upon the exact instructions generated by the compiler - thus breaking program logic/invariants. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4445" title="#4445: Bugs: boost:math::float_advance( 0.0, 2 ) stack overflows if denormal ... (closed: fixed)">#4445</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 29 Nov 2012 11:07:51 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4445#comment:3 https://svn.boost.org/trac10/ticket/4445#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> </ul> <p> As I believe this is basically as fixed as it's possible to be (which is to say not completely!), I'm closing the issue for now. </p> Ticket