[Boost-bugs] [Boost C++ Libraries] #9672: PDF and CDF of a laplace distribution throwing domain_error

Subject: [Boost-bugs] [Boost C++ Libraries] #9672: PDF and CDF of a laplace distribution throwing domain_error
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-02-17 06:36:01

#9672: PDF and CDF of a laplace distribution throwing domain_error
 Reporter: HS <tan@…> | Owner: johnmaddock
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: math
  Version: Boost Development Trunk | Severity: Showstopper
 Keywords: |

 I would expect the following to behave just like a normal distribution (or
 a cauchy distribution) at x=+-infinity:

 // #define BOOST_MATH_DOMAIN_ERROR_POLICY ignore_error

 #include <cstdlib>
 #include <cstdio>

 #include <limits>

 #include <boost/math/distributions/cauchy.hpp>
 #include <boost/math/distributions/laplace.hpp>
 #include <boost/math/distributions/normal.hpp>

 static const double INFTY = std::numeric_limits< double >::infinity();

 template< typename T >
 void TestBoundary( const char* distName, const T& t )
          "%15s ---------------------\n"
          "%15s %'*g %'*g\n",
          boost::math::pdf( t, -INFTY ), 10,
          boost::math::pdf( t, INFTY ), 10 );

          "%15s %'*g %'*g\n",
          boost::math::cdf( t, -INFTY ), 10,
          boost::math::cdf( t, INFTY ), 10 );

          "%15s %'*g %'*g\n",
          boost::math::cdf( boost::math::complement( t, -INFTY ) ), 10,
          boost::math::cdf( boost::math::complement( t, INFTY ) ), 10 );

 int main()
          "%15s %10s %10s\n",
          "x=+infty" );

    double _location = 3.2;
    double _scale = 0.7;

       boost::math::normal_distribution<>( _location, _scale ) );

       boost::math::cauchy_distribution<>( _location, _scale ) );

    // To NOT throw domain_error exception at infinity?
       boost::math::laplace_distribution<>( _location, _scale ) );

    return EXIT_SUCCESS;

 Simply compile with "g++ filename.cpp" and obtain the following when the
 resulting executable is ran:
 terminate called after throwing an instance of
 what(): Error in function boost::math::pdf(const
 laplace_distribution<d>&, d)): Random variate x is inf, but must be

 If a random variable is documented to have a domain [-infty,
 +infty]---notice the closed interval, does it mean that the implementation
 will honor it (in that it would return the valid PDF or CDF at any value
 of the domain)---see the line above the graph of the PDF on
 I assumed it meant to say the "domain of the random variable" instead of
 "the range of the random variable" (the last expression under ''Non-member
 Accessors'' paragraph has it right).

 Thank you.[[br]]

 P.S. The following is from "git log -2" inside libs/math:
 commit ec438ff39d855f810e236dbaf14b8755f7157869
 Author: Beman <bdawes_at_[hidden]>
 Date: Sun Dec 1 09:14:12 2013 -0500

     End-of-line normalization. Most normalization was taken care of by
 .gitattributes, but a few files originally committed to svn with incorrect
 eol tags need explicit normalization. See .gitattributes man page and
 extensive list discussion.

 commit fb52d2de42ff7e1cbc61103a25fbc82c5e034a90
 Author: John Maddock <john_at_[hidden]>
 Date: Thu Oct 24 08:35:41 2013 +0000

     Fix initialization of power series so that we don't get a spurious
 overflow error from tgamma when the res
 ult is actually zero.

     [SVN r86415]

Ticket URL: <https://svn.boost.org/trac/boost/ticket/9672>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC