Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#10111 closed Bugs (fixed)

quantile at p=1 for non-central chi-squared---regression bug?

Reported by: HS <tan@…> Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost Development Trunk Severity: Regression
Keywords: Cc:

Description

I think this used to work as expected a while ago:

#include <cstdlib>
#include <cstdio>

#include <boost/math/distributions/non_central_chi_squared.hpp>
#include <boost/math/distributions/chi_squared.hpp>

int main()
{
   const double _df = 1.2;
   const double _nc = 2.5;

   const double _p = 1.0;

   std::printf(
         "\nchi-squared: quantile( p=%g, df=%g ) = %g\n",
         _p, _df,
         boost::math::quantile(
            boost::math::chi_squared_distribution<>( _df ),
            _p ) );

   std::printf(
         "non-central chi-squared: quantile( p=%g, df=%g, nc=%g ) = %g\n\n",
         _p, _df, _nc,
         boost::math::quantile(
            boost::math::non_central_chi_squared_distribution<>( _df, _nc ),
            _p ) );

   return EXIT_SUCCESS;
}

When built with "g++ -o test chisq.cpp" (after saving the above as "chisq.cpp") on a Linux box, this currently returns

chi-squared: quantile( p=1, df=1.2 ) = inf
non-central chi-squared: quantile( p=1, df=1.2, nc=2.5 ) = 1.79769e+308

when ran; I expected both to return inf.

Thank you,
HS

Change History (3)

comment:1 by John Maddock, 8 years ago

Actually the first case returns infinity "by accident", so they're both buggy - they should be raising an overflow_error instead. Fixed in https://github.com/boostorg/math/commit/ee8edd4c335c3592b0585ddcf623d739defc1fa3.

Note that the default behaviour is now for these cases to throw a std::overflow_error, if you want them to return infinity instead then you'll need to change the policy defaults, for example as in http://www.boost.org/doc/libs/1_55_0/libs/math/doc/html/math_toolkit/pol_ref/policy_defaults.html

comment:2 by John Maddock, 8 years ago

Resolution: fixed
Status: newclosed

comment:3 by HS <tan@…>, 8 years ago

Thank you, John, for the quick fix(es). Yes, I actually do use the ignore_error for the BOOST_MATH_DOMAIN_ERROR_POLICY in my original code.

With best regards,
HS

Note: See TracTickets for help on using tickets.