diff options
Diffstat (limited to 'boost/math/distributions/normal.hpp')
-rw-r--r-- | boost/math/distributions/normal.hpp | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/boost/math/distributions/normal.hpp b/boost/math/distributions/normal.hpp index baeecf6348..32cf66e3ef 100644 --- a/boost/math/distributions/normal.hpp +++ b/boost/math/distributions/normal.hpp @@ -31,14 +31,14 @@ public: typedef RealType value_type; typedef Policy policy_type; - normal_distribution(RealType mean = 0, RealType sd = 1) - : m_mean(mean), m_sd(sd) + normal_distribution(RealType l_mean = 0, RealType sd = 1) + : m_mean(l_mean), m_sd(sd) { // Default is a 'standard' normal distribution N01. static const char* function = "boost::math::normal_distribution<%1%>::normal_distribution"; RealType result; detail::check_scale(function, sd, &result, Policy()); - detail::check_location(function, mean, &result, Policy()); + detail::check_location(function, l_mean, &result, Policy()); } RealType mean()const @@ -71,22 +71,43 @@ private: typedef normal_distribution<double> normal; +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4127) +#endif + template <class RealType, class Policy> inline const std::pair<RealType, RealType> range(const normal_distribution<RealType, Policy>& /*dist*/) { // Range of permissible values for random variable x. - using boost::math::tools::max_value; - return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + max value. + if (std::numeric_limits<RealType>::has_infinity) + { + return std::pair<RealType, RealType>(-std::numeric_limits<RealType>::infinity(), std::numeric_limits<RealType>::infinity()); // - to + infinity. + } + else + { // Can only use max_value. + using boost::math::tools::max_value; + return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + max value. + } } template <class RealType, class Policy> inline const std::pair<RealType, RealType> support(const normal_distribution<RealType, Policy>& /*dist*/) -{ // Range of supported values for random variable x. - // This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. - +{ // This is range values for random variable x where cdf rises from 0 to 1, and outside it, the pdf is zero. + if (std::numeric_limits<RealType>::has_infinity) + { + return std::pair<RealType, RealType>(-std::numeric_limits<RealType>::infinity(), std::numeric_limits<RealType>::infinity()); // - to + infinity. + } + else + { // Can only use max_value. using boost::math::tools::max_value; return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + max value. + } } +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + template <class RealType, class Policy> inline RealType pdf(const normal_distribution<RealType, Policy>& dist, const RealType& x) { @@ -96,15 +117,6 @@ inline RealType pdf(const normal_distribution<RealType, Policy>& dist, const Rea RealType mean = dist.mean(); static const char* function = "boost::math::pdf(const normal_distribution<%1%>&, %1%)"; - if((boost::math::isinf)(x)) - { - return 0; // pdf + and - infinity is zero. - } - // Below produces MSVC 4127 warnings, so the above used instead. - //if(std::numeric_limits<RealType>::has_infinity && abs(x) == std::numeric_limits<RealType>::infinity()) - //{ // pdf + and - infinity is zero. - // return 0; - //} RealType result = 0; if(false == detail::check_scale(function, sd, &result, Policy())) @@ -115,6 +127,15 @@ inline RealType pdf(const normal_distribution<RealType, Policy>& dist, const Rea { return result; } + if((boost::math::isinf)(x)) + { + return 0; // pdf + and - infinity is zero. + } + // Below produces MSVC 4127 warnings, so the above used instead. + //if(std::numeric_limits<RealType>::has_infinity && abs(x) == std::numeric_limits<RealType>::infinity()) + //{ // pdf + and - infinity is zero. + // return 0; + //} if(false == detail::check_x(function, x, &result, Policy())) { return result; @@ -204,6 +225,11 @@ inline RealType cdf(const complemented2_type<normal_distribution<RealType, Polic RealType x = c.param; static const char* function = "boost::math::cdf(const complement(normal_distribution<%1%>&), %1%)"; + RealType result = 0; + if(false == detail::check_scale(function, sd, &result, Policy())) + return result; + if(false == detail::check_location(function, mean, &result, Policy())) + return result; if((boost::math::isinf)(x)) { if(x < 0) return 1; // cdf complement -infinity is unity. @@ -218,11 +244,6 @@ inline RealType cdf(const complemented2_type<normal_distribution<RealType, Polic //{ // cdf complement -infinity is unity. // return 1; //} - RealType result = 0; - if(false == detail::check_scale(function, sd, &result, Policy())) - return result; - if(false == detail::check_location(function, mean, &result, Policy())) - return result; if(false == detail::check_x(function, x, &result, Policy())) return result; |