Opened 7 years ago

Closed 5 years ago

#4445 closed Bugs (fixed)

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

Reported by: Emmet Spier <emmet.spier@…> Owned by: John Maddock
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;


Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by John Maddock

Owner: changed from Douglas Gregor to John Maddock

comment:2 Changed 5 years ago by John Maddock

(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 5 years ago by John Maddock

Resolution: fixed
Status: newclosed

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.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain John Maddock.
The resolution will be deleted.

Add Comment

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

Note: See TracTickets for help on using tickets.