Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67212 - trunk/boost/math/distributions
From: pbristow_at_[hidden]
Date: 2010-12-13 11:36:02


Author: pbristow
Date: 2010-12-13 11:35:59 EST (Mon, 13 Dec 2010)
New Revision: 67212
URL: http://svn.boost.org/trac/boost/changeset/67212

Log:
use raise_overflow error in place of return NaN
Text files modified:
   trunk/boost/math/distributions/laplace.hpp | 30 +++++++++++++++++-------------
   1 files changed, 17 insertions(+), 13 deletions(-)

Modified: trunk/boost/math/distributions/laplace.hpp
==============================================================================
--- trunk/boost/math/distributions/laplace.hpp (original)
+++ trunk/boost/math/distributions/laplace.hpp 2010-12-13 11:35:59 EST (Mon, 13 Dec 2010)
@@ -66,23 +66,17 @@
          return true;
    }
 
-
 private:
    RealType m_location;
    RealType m_scale;
-
 }; // class laplace_distribution
 
-
-
-//
-// Convenient type synonym
 //
+// Convenient type synonym for double
 typedef laplace_distribution<double> laplace;
 
 //
 // Non member functions
-//
 template <class RealType, class Policy>
 inline const std::pair<RealType, RealType> range(const laplace_distribution<RealType, Policy>&)
 {
@@ -137,7 +131,7 @@
    if (false == dist.check_parameters(function, &result)) return result;
    if (false == detail::check_x(function, x, &result, Policy())) return result;
 
- // Special cdf values
+ // Special cdf values:
    if((boost::math::isinf)(x))
    {
      if(x < 0) return 0; // -infinity
@@ -160,7 +154,7 @@
 template <class RealType, class Policy>
 inline RealType quantile(const laplace_distribution<RealType, Policy>& dist, const RealType& p)
 {
- BOOST_MATH_STD_USING // for ADL of std functions
+ BOOST_MATH_STD_USING // for ADL of std functions.
 
    // Checking function argument
    RealType result;
@@ -168,10 +162,20 @@
    if (false == dist.check_parameters(function, &result)) return result;
    if(false == detail::check_probability(function, p, &result, Policy())) return result;
 
- // extreme values
- if(p == 0) return -std::numeric_limits<RealType>::infinity();
- if(p == 1) return std::numeric_limits<RealType>::infinity();
-
+ // Extreme values of p:
+ if(p == 0)
+ {
+ result = policies::raise_overflow_error<RealType>(function,
+ "probability parameter is 0, but must be > 0!", Policy());
+ return -result; // -std::numeric_limits<RealType>::infinity();
+ }
+
+ if(p == 1)
+ {
+ result = policies::raise_overflow_error<RealType>(function,
+ "probability parameter is 1, but must be < 1!", Policy());
+ return result; // std::numeric_limits<RealType>::infinity();
+ }
    // Calculate Quantile
    RealType scale( dist.scale() );
    RealType location( dist.location() );


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk