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: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | Boost 1.44.0 | Component: | math |
Version: | Boost 1.40.0 | Severity: | Showstopper |
Keywords: | Cc: |
Description
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
Owner: | changed from Douglas Gregor to John Maddock |
---|
comment:2 Changed 5 years ago by
comment:3 Changed 5 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
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.
(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.