Opened 7 years ago

Closed 7 years ago

#11272 closed Bugs (fixed)

Incorrect use of abs() function in libs/math/example/normal_misc_examples.cpp

Reported by: Quentin Armitage <quentin@…> Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc:

Description

When running normal_misc_examples, it produces the following error:

If we want the 0.0500 th quantile to be located at 2.90, would need a standard deviation of 0.00

Message from thrown exception was:
   Error in function boost::math::normal_distribution<double>::normal_distribution: Scale parameter is 0, but must be > 0 !

The reason for this is line 373:

double sd95 = abs((x - mean)) / qp;

where the abs() function is the C function which takes an int parameter. Passing it the double (x - mean) returns 0.

As a temporary workaround, I have modified the code to

double sd95 = (x - mean) / qp;
if (sd95 < 0)
    sd95 = -sd95 ;

and this resolves the problem.

Change History (1)

comment:1 by John Maddock, 7 years ago

Resolution: fixed
Status: newclosed

abs is overloaded for floating point types in C++, but of course the call should be to std::abs. Fixed in https://github.com/boostorg/math/commit/282a74beea5686b1d3f949e9328b455d9374aa34

Note: See TracTickets for help on using tickets.