Ticket #4445 (closed Bugs: fixed)

Opened 5 years ago

Last modified 2 years ago

boost:math::float_advance( 0.0, 2 ) stack overflows if denormal numbers are set to zero

Reported by: Emmet Spier <emmet.spier@…> Owned by: johnmaddock
Milestone: Boost 1.44.0 Component: math
Version: Boost 1.40.0 Severity: Showstopper
Keywords: Cc:


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.

Ultimately given the current code, this is because boost::math::sign( denormal number ) == 0 as opposed to the sign of the denormal number.

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.

Example code, built with optimisations enabled

#include <boost/math/special_functions/next.hpp>

#include <ippcore.h>

int main() {

double thisWillWork = boost::math::float_advance( 0.0, 2 ); ippSetDenormAreZeros(1); or set MXCSR bit six directly double thisWillStackOverFlow = boost::math::float_advance( 0.0, 2 );

return 0;



Change History

comment:1 Changed 3 years ago by johnmaddock

  • Owner changed from dgregor to johnmaddock

comment:2 Changed 3 years ago by johnmaddock

(In [79572]) Tentative fix for issue #4445. 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 #4445.

comment:3 Changed 2 years ago by johnmaddock

  • Status changed from new to closed
  • Resolution set to fixed

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.


Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.