Boost logo

Boost-Commit :

From: pbristow_at_[hidden]
Date: 2007-09-16 06:09:52


Author: pbristow
Date: 2007-09-16 06:09:51 EDT (Sun, 16 Sep 2007)
New Revision: 39310
URL: http://svn.boost.org/trac/boost/changeset/39310

Log:
changed to allow pdf and cdf infinity.
Text files modified:
   sandbox/math_toolkit/boost/math/distributions/normal.hpp | 24 ++++++++++++++++++++++++
   1 files changed, 24 insertions(+), 0 deletions(-)

Modified: sandbox/math_toolkit/boost/math/distributions/normal.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/normal.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/normal.hpp 2007-09-16 06:09:51 EDT (Sun, 16 Sep 2007)
@@ -96,6 +96,11 @@
 
    static const char* function = "boost::math::pdf(const normal_distribution<%1%>&, %1%)";
 
+ if(std::numeric_limits<RealType>::has_infinity && abs(x) == std::numeric_limits<RealType>::infinity())
+ { // pdf + and - infinity is zero.
+ return 0;
+ }
+
    RealType result;
    if(false == detail::check_scale(function, sd, &result, Policy()))
       return result;
@@ -122,6 +127,16 @@
    RealType sd = dist.standard_deviation();
    RealType mean = dist.mean();
    static const char* function = "boost::math::cdf(const normal_distribution<%1%>&, %1%)";
+
+ if(std::numeric_limits<RealType>::has_infinity && x == std::numeric_limits<RealType>::infinity())
+ { // cdf +infinity is unity.
+ return 1;
+ }
+ if(std::numeric_limits<RealType>::has_infinity && x == -std::numeric_limits<RealType>::infinity())
+ { // cdf -infinity is zero.
+ return 0;
+ }
+
    RealType result;
    if(false == detail::check_scale(function, sd, &result, Policy()))
       return result;
@@ -169,6 +184,15 @@
    RealType mean = c.dist.mean();
    RealType x = c.param;
    static const char* function = "boost::math::cdf(const complement(normal_distribution<%1%>&), %1%)";
+
+ if(std::numeric_limits<RealType>::has_infinity && x == std::numeric_limits<RealType>::infinity())
+ { // cdf +infinity is zero.
+ return 0;
+ }
+ if(std::numeric_limits<RealType>::has_infinity && x == -std::numeric_limits<RealType>::infinity())
+ { // cdf -infinity is unity.
+ return 1;
+ }
    RealType result;
    if(false == detail::check_scale(function, sd, &result, Policy()))
       return result;


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