Boost logo

Boost-Commit :

From: pbristow_at_[hidden]
Date: 2007-09-17 05:17:43


Author: pbristow
Date: 2007-09-17 05:17:42 EDT (Mon, 17 Sep 2007)
New Revision: 39343
URL: http://svn.boost.org/trac/boost/changeset/39343

Log:
4127 warning squashed
Text files modified:
   sandbox/math_toolkit/boost/math/distributions/cauchy.hpp | 154 ++++++++++++++++++++++++---------------
   sandbox/math_toolkit/boost/math/distributions/detail/common_error_handling.hpp | 12 +-
   sandbox/math_toolkit/boost/math/distributions/find_location.hpp | 66 +++++++++++++++--
   sandbox/math_toolkit/boost/math/distributions/find_scale.hpp | 126 +++++++++++++++++++++++++-------
   sandbox/math_toolkit/boost/math/distributions/normal.hpp | 62 ++++++++++-----
   5 files changed, 295 insertions(+), 125 deletions(-)

Modified: sandbox/math_toolkit/boost/math/distributions/cauchy.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/cauchy.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/cauchy.hpp 2007-09-17 05:17:42 EDT (Mon, 17 Sep 2007)
@@ -1,4 +1,4 @@
-// Copyright John Maddock 2006.
+// Copyright John Maddock 2006, 2007.
 // Copyright Paul A. Bristow 2007.
 
 // Use, modification and distribution are subject to the
@@ -8,17 +8,17 @@
 #ifndef BOOST_STATS_CAUCHY_HPP
 #define BOOST_STATS_CAUCHY_HPP
 
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4127) // conditional expression is constant
+#endif
+
 #include <boost/math/distributions/fwd.hpp>
 #include <boost/math/constants/constants.hpp>
 #include <boost/math/distributions/complement.hpp>
 #include <boost/math/distributions/detail/common_error_handling.hpp>
 #include <cmath>
 
-#ifdef BOOST_MSVC
-# pragma warning(push)
-# pragma warning(disable: 4702) // unreachable code (return after raise_domain_error throw).
-#endif
-
 #include <utility>
 
 namespace boost{ namespace math
@@ -31,20 +31,6 @@
 {
 
 template <class RealType, class Policy>
-inline bool check_cauchy_scale(const char* func, RealType scale, RealType* result, const Policy& pol)
-{
- if(scale <= 0)
- {
- *result = policies::raise_domain_error<RealType>(
- func,
- "The scale parameter for the Cauchy distribution must be > 0 but got %1%.",
- scale, pol);
- return false;
- }
- return true;
-}
-
-template <class RealType, class Policy>
 RealType cdf_imp(const cauchy_distribution<RealType, Policy>& dist, const RealType& x, bool complement)
 {
    //
@@ -69,21 +55,37 @@
    // to get the result.
    //
    BOOST_MATH_STD_USING // for ADL of std functions
-
+ static const char* function = "boost::math::cdf(cauchy<%1%>&, %1%)";
    RealType result;
- RealType loc = dist.location();
+ RealType location = dist.location();
    RealType scale = dist.scale();
- if(0 == detail::check_cauchy_scale("boost::math::cdf(cauchy<%1%>&, %1%)", scale, &result, Policy()))
+ if(false == detail::check_location(function, location, &result, Policy()))
+ {
+ return result;
+ }
+ if(false == detail::check_scale(function, scale, &result, Policy()))
+ {
       return result;
- RealType mx = -fabs((x - loc) / scale);
-
- // special case first:
+ }
+ if(std::numeric_limits<RealType>::has_infinity && x == std::numeric_limits<RealType>::infinity())
+ { // cdf +infinity is unity.
+ return static_cast<RealType>((complement) ? 0 : 1);
+ }
+ if(std::numeric_limits<RealType>::has_infinity && x == -std::numeric_limits<RealType>::infinity())
+ { // cdf -infinity is zero.
+ return static_cast<RealType>((complement) ? 1 : 0);
+ }
+ if(false == detail::check_x(function, x, &result, Policy()))
+ { // Catches x == NaN
+ return result;
+ }
+ RealType mx = -fabs((x - location) / scale); // scale is > 0
    if(mx > -tools::epsilon<RealType>() / 8)
+ { // special case first: x extremely close to location.
       return 0.5;
-
+ }
    result = -atan(1 / mx) / constants::pi<RealType>();
-
- return (((x > loc) != complement) ? 1 - result : result);
+ return (((x > location) != complement) ? 1 - result : result);
 } // cdf
 
 template <class RealType, class Policy>
@@ -92,40 +94,53 @@
       const RealType& p,
       bool complement)
 {
+ // This routine implements the quantile for the Cauchy distribution,
+ // the value p may be the probability, or its complement if complement=true.
    //
- // This routine implements the quantile for the Cauchy distibution,
- // the value p may be the probability or it's complement if complement=true.
- //
- // The proceedure first performs argument reduction on p to avoid error
+ // The procedure first performs argument reduction on p to avoid error
    // when calculating the tangent, then calulates the distance from the
    // mid-point of the distribution. This is either added or subtracted
    // from the location parameter depending on whether `complement` is true.
    //
    static const char* function = "boost::math::quantile(cauchy<%1%>&, %1%)";
    BOOST_MATH_STD_USING // for ADL of std functions
- // Special cases:
- if(p == 1)
- return (complement ? -1 : 1) * policies::raise_overflow_error<RealType>(function, 0, Policy());
- if(p == 0)
- return (complement ? 1 : -1) * policies::raise_overflow_error<RealType>(function, 0, Policy());
 
    RealType result;
- RealType loc = dist.location();
+ RealType location = dist.location();
    RealType scale = dist.scale();
- if(0 == detail::check_cauchy_scale(function, scale, &result, Policy()))
+ if(false == detail::check_location(function, location, &result, Policy()))
+ {
+ return result;
+ }
+ if(false == detail::check_scale(function, scale, &result, Policy()))
+ {
       return result;
- if(0 == detail::check_probability(function, p, &result, Policy()))
+ }
+ if(false == detail::check_probability(function, p, &result, Policy()))
+ {
       return result;
+ }
+ // Special cases:
+ if(p == 1)
+ {
+ return (complement ? -1 : 1) * policies::raise_overflow_error<RealType>(function, 0, Policy());
+ }
+ if(p == 0)
+ {
+ return (complement ? 1 : -1) * policies::raise_overflow_error<RealType>(function, 0, Policy());
+ }
 
- // argument reduction of p:
- RealType P = p - floor(p);
+ RealType P = p - floor(p); // argument reduction of p:
    if(P > 0.5)
+ {
       P = P - 1;
- // special case:
- if(P == 0.5)
- return loc;
+ }
+ if(P == 0.5) // special case:
+ {
+ return location;
+ }
    result = -scale / tan(constants::pi<RealType>() * P);
- return complement ? loc - result : loc + result;
+ return complement ? location - result : location + result;
 } // quantile
 
 } // namespace detail
@@ -137,11 +152,13 @@
    typedef RealType value_type;
    typedef Policy policy_type;
 
- cauchy_distribution(RealType a = 0, RealType b = 1)
- : m_a(a), m_hg(b)
+ cauchy_distribution(RealType location = 0, RealType scale = 1)
+ : m_a(location), m_hg(scale)
    {
- RealType r;
- detail::check_cauchy_scale("boost::math::cauchy<%1%>::cauchy", b, &r, Policy());
+ static const char* function = "boost::math::cauchy_distribution<%1%>::cauchy_distribution";
+ RealType result;
+ detail::check_location(function, location, &result, Policy());
+ detail::check_scale(function, scale, &result, Policy());
    } // cauchy_distribution
 
    RealType location()const
@@ -154,8 +171,8 @@
    }
 
 private:
- RealType m_a; // The location, this is the median of the distribution
- RealType m_hg; // The scale, this is the half width at half height.
+ RealType m_a; // The location, this is the median of the distribution.
+ RealType m_hg; // The scale )or shape), this is the half width at half height.
 };
 
 typedef cauchy_distribution<double> cauchy;
@@ -176,15 +193,30 @@
 
 template <class RealType, class Policy>
 inline RealType pdf(const cauchy_distribution<RealType, Policy>& dist, const RealType& x)
-{
+{
+ static const char* function = "boost::math::pdf(cauchy<%1%>&, %1%)";
    RealType result;
- RealType loc = dist.location();
+ RealType location = dist.location();
    RealType scale = dist.scale();
- if(0 == detail::check_cauchy_scale("boost::math::pdf(cauchy<%1%>&, %1%)", scale, &result, Policy()))
+ if(false == detail::check_scale("boost::math::pdf(cauchy<%1%>&, %1%)", scale, &result, Policy()))
+ {
+ return result;
+ }
+ if(false == detail::check_location("boost::math::pdf(cauchy<%1%>&, %1%)", location, &result, Policy()))
+ {
       return result;
+ }
 
- RealType xs = (x - loc) / scale;
+ 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()))
+ { // Catches x = NaN
+ return result;
+ }
 
+ RealType xs = (x - location) / scale;
    result = 1 / (constants::pi<RealType>() * scale * (1 + xs * xs));
    return result;
 } // pdf
@@ -205,13 +237,13 @@
 inline RealType cdf(const complemented2_type<cauchy_distribution<RealType, Policy>, RealType>& c)
 {
    return detail::cdf_imp(c.dist, c.param, true);
-}
+} // cdf complement
 
 template <class RealType, class Policy>
 inline RealType quantile(const complemented2_type<cauchy_distribution<RealType, Policy>, RealType>& c)
 {
    return detail::quantile_imp(c.dist, c.param, true);
-}
+} // quantile complement
 
 template <class RealType, class Policy>
 inline RealType mean(const cauchy_distribution<RealType, Policy>&)
@@ -296,8 +328,8 @@
 } // namespace math
 } // namespace boost
 
-#ifdef BOOST_MSVC
-# pragma warning(pop)
+#ifdef _MSC_VER
+#pragma warning(pop)
 #endif
 
 // This include must be at the end, *after* the accessors

Modified: sandbox/math_toolkit/boost/math/distributions/detail/common_error_handling.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/detail/common_error_handling.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/detail/common_error_handling.hpp 2007-09-17 05:17:42 EDT (Mon, 17 Sep 2007)
@@ -1,4 +1,4 @@
-// Copyright John Maddock 2006.
+// Copyright John Maddock 2006, 2007.
 // Copyright Paul A. Bristow 2006, 2007.
 
 // Use, modification and distribution are subject to the
@@ -79,21 +79,23 @@
 template <class RealType, class Policy>
 inline bool check_x(
       const char* function,
- RealType location,
+ RealType x,
       RealType* result,
       const Policy& pol)
 {
- if(!(boost::math::isfinite)(location))
+ if(!(boost::math::isfinite)(x))
    {
       *result = policies::raise_domain_error<RealType>(
          function,
- "Random variate x is %1%, but must be finite!", location, pol);
+ "Random variate x is %1%, but must be finite!", x, pol);
       return false;
    }
    return true;
+ // Note that this test catches both infinity and NaN.
+ // Some special cases permit x to be infinite, so these must be tested 1st,
+ // leaving this test to catch any NaNs. see Normal and cauchy for example.
 }
 
-
 } // namespace detail
 } // namespace math
 } // namespace boost

Modified: sandbox/math_toolkit/boost/math/distributions/find_location.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/find_location.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/find_location.hpp 2007-09-17 05:17:42 EDT (Mon, 17 Sep 2007)
@@ -23,8 +23,8 @@
   {
   // Function to find location of random variable z
   // to give probability p (given scale)
- // Apply to normal, lognormal, extreme value, Cauchy, (and symmetrical triangular).
- // TODO use concepts to enforce this.
+ // Applies to normal, lognormal, extreme value, Cauchy, (and symmetrical triangular),
+ // enforced by BOOST_STATIC_ASSERT below.
 
     template <class Dist, class Policy>
     inline
@@ -37,8 +37,10 @@
       )
     {
       BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value);
- BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
- static const char* function = "boost::math::find_location<%1%>&, %1%)";
+ BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
+ // Will fail to compile here if try to use with a distribution without scale & location,
+ // for example pareto, and many others.
+ static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
 
       if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
       {
@@ -76,13 +78,61 @@
     // for example, l = find_location<normal>(complement(z, q, sd));
 
     template <class Dist, class Real1, class Real2, class Real3>
- inline typename Dist::value_type find_location(
+ inline typename Dist::value_type find_location( // Default policy.
       complemented3_type<Real1, Real2, Real3> const& c)
     {
+ static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
+
+ Dist::value_type p = c.param1;
+ if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, policies::policy<>());
+ }
+ Dist::value_type z = c.dist;
+ if(!(boost::math::isfinite)(z))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "z parameter was %1%, but must be finite!", z, policies::policy<>());
+ }
+ Dist::value_type scale = c.param2;
+ if(!(boost::math::isfinite)(scale))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "scale parameter was %1%, but must be finite!", scale, policies::policy<>());
+ }
+ // cout << "z " << c.dist << ", quantile (Dist(), " << c.param1 << ") * scale " << c.param2 << endl;
+ return z - quantile(Dist(), p) * scale;
+ } // find_location complement
+
+
+ template <class Dist, class Real1, class Real2, class Real3, class Real4>
+ inline typename Dist::value_type find_location( // Explicit policy.
+ complemented4_type<Real1, Real2, Real3, Real4> const& c)
+ {
+ static const char* function = "boost::math::find_location<Dist, Policy>&, %1%)";
+
+ Dist::value_type p = c.param1;
+ if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, c.param3);
+ }
+ Dist::value_type z = c.dist;
+ if(!(boost::math::isfinite)(z))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "z parameter was %1%, but must be finite!", z, c.param3);
+ }
+ Dist::value_type scale = c.param2;
+ if(!(boost::math::isfinite)(scale))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "scale parameter was %1%, but must be finite!", scale, c.param3);
+ }
        // cout << "z " << c.dist << ", quantile (Dist(), " << c.param1 << ") * scale " << c.param2 << endl;
- return c.dist - quantile(Dist(), c.param1) * c.param2;
- // z - (quantile(Dist(), p) * scale
- }
+ return z - quantile(Dist(), p) * scale;
+ } // find_location complement
 
   } // namespace boost
 } // namespace math

Modified: sandbox/math_toolkit/boost/math/distributions/find_scale.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/distributions/find_scale.hpp (original)
+++ sandbox/math_toolkit/boost/math/distributions/find_scale.hpp 2007-09-17 05:17:42 EDT (Mon, 17 Sep 2007)
@@ -21,11 +21,11 @@
 {
   namespace math
   {
- // Function to find location of random variable z
- // to give probability p (given scale)
- // Applies to normal, lognormal, extreme value, Cauchy, (and symmetrical triangular),
- // distributions that have scale.
- // BOOST_STATIC_ASSERTs, see below, are used to enforce this.
+ // Function to find location of random variable z
+ // to give probability p (given scale)
+ // Applies to normal, lognormal, extreme value, Cauchy, (and symmetrical triangular),
+ // distributions that have scale.
+ // BOOST_STATIC_ASSERTs, see below, are used to enforce this.
 
     template <class Dist, class Policy>
     inline
@@ -43,20 +43,20 @@
 
       if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
       {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, pol);
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, pol);
       }
       if(!(boost::math::isfinite)(z))
       {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "find_scale z parameter was %1%, but must be finite!", z, pol);
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "find_scale z parameter was %1%, but must be finite!", z, pol);
       }
       if(!(boost::math::isfinite)(location))
       {
- return policies::raise_domain_error<typename Dist::value_type>(
- function, "find_scale location parameter was %1%, but must be finite!", location, pol);
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "find_scale location parameter was %1%, but must be finite!", location, pol);
       }
-
+
       //cout << "z " << z << ", p " << p << ", quantile(Dist(), p) "
       //<< quantile(Dist(), p) << ", z - mean " << z - location
       //<<", sd " << (z - location) / quantile(Dist(), p) << endl;
@@ -73,17 +73,17 @@
       //quantile(N01, 0.999) 3.09023
 
       Dist::value_type result =
- (z - location) // difference between desired x and current location.
- / quantile(Dist(), p); // standard distribution.
+ (z - location) // difference between desired x and current location.
+ / quantile(Dist(), p); // standard distribution.
 
       if (result <= 0)
       { // If policy isn't to throw, return the scale <= 0.
         policies::raise_evaluation_error<Dist::value_type>(function,
           "Computed scale (%1%) is <= 0!" " Was the complement intended?",
- result, Policy());
+ result, Policy());
       }
       return result;
- } // find_scale
+ } // template <class Dist, class Policy> find_scale
 
     template <class Dist>
     inline // with default policy.
@@ -93,9 +93,58 @@
       typename Dist::value_type p, // probability value desired at x, say 0.95 for 95% > z.
       typename Dist::value_type location) // location parameter, for example, mean.
     { // Forward to find_scale using the default policy.
- return (find_scale<Dist>(z, p, location, policies::policy<>()));
+ return (find_scale<Dist>(z, p, location, policies::policy<>()));
     } // find_scale
 
+ template <class Dist, class Real1, class Real2, class Real3, class Policy>
+ inline typename Dist::value_type find_scale(
+ complemented4_type<Real1, Real2, Real3, Policy> const& c)
+ {
+ //cout << "cparam1 q " << c.param1 // q
+ // << ", c.dist z " << c.dist // z
+ // << ", c.param2 l " << c.param2 // l
+ // << ", quantile (Dist(), c.param1 = q) "
+ // << quantile(Dist(), c.param1) //q
+ // << endl;
+
+ BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value);
+ BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
+ static const char* function = "boost::math::find_scale<Dist, Policy>(complement(%1%, %1%, %1%, Policy))";
+
+ // Checks on arguments, as not complemented version,
+ // Explicit policy.
+ Dist::value_type q = c.param1;
+ if(!(boost::math::isfinite)(q) || (q < 0) || (q > 1))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "Probability parameter was %1%, but must be >= 0 and <= 1!", q, c.param3);
+ }
+ Dist::value_type z = c.dist;
+ if(!(boost::math::isfinite)(z))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "find_scale z parameter was %1%, but must be finite!", z, c.param3);
+ }
+ Dist::value_type location = c.param2;
+ if(!(boost::math::isfinite)(location))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "find_scale location parameter was %1%, but must be finite!", location, c.param3);
+ }
+
+ Dist::value_type result =
+ (c.dist - c.param2) // difference between desired x and current location.
+ / quantile(complement(Dist(), c.param1));
+ // ( z - location) / (quantile(complement(Dist(), q))
+ if (result <= 0)
+ { // If policy isn't to throw, return the scale <= 0.
+ policies::raise_evaluation_error<Dist::value_type>(function,
+ "Computed scale (%1%) is <= 0!" " Was the complement intended?",
+ result, Policy());
+ }
+ return result;
+ } // template <class Dist, class Policy, class Real1, class Real2, class Real3> typename Dist::value_type find_scale
+
     // So the user can start from the complement q = (1 - p) of the probability p,
     // for example, s = find_scale<normal>(complement(z, q, l));
 
@@ -110,23 +159,44 @@
       // << quantile(Dist(), c.param1) //q
       // << endl;
 
- BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value);
- BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
- static const char* function = "boost::math::find_scale<Dist, Policy>(complement(%1%, %1%, %1%, Policy))";
+ BOOST_STATIC_ASSERT(::boost::math::tools::is_distribution<Dist>::value);
+ BOOST_STATIC_ASSERT(::boost::math::tools::is_scaled_distribution<Dist>::value);
+ static const char* function = "boost::math::find_scale<Dist, Policy>(complement(%1%, %1%, %1%, Policy))";
+
+ // Checks on arguments, as not complemented version,
+ // default policy policies::policy<>().
+ Dist::value_type q = c.param1;
+ if(!(boost::math::isfinite)(q) || (q < 0) || (q > 1))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "Probability parameter was %1%, but must be >= 0 and <= 1!", q, policies::policy<>());
+ }
+ Dist::value_type z = c.dist;
+ if(!(boost::math::isfinite)(z))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "find_scale z parameter was %1%, but must be finite!", z, policies::policy<>());
+ }
+ Dist::value_type location = c.param2;
+ if(!(boost::math::isfinite)(location))
+ {
+ return policies::raise_domain_error<typename Dist::value_type>(
+ function, "find_scale location parameter was %1%, but must be finite!", location, policies::policy<>());
+ }
 
       Dist::value_type result =
- (c.dist - c.param2) // difference between desired x and current location.
- / quantile(complement(Dist(), c.param1));
+ (z - location) // difference between desired x and current location.
+ / quantile(complement(Dist(), q));
       // ( z - location) / (quantile(complement(Dist(), q))
- if (result <= 0)
- { // If policy isn't to throw, return the scale <= 0.
+ if (result <= 0)
+ { // If policy isn't to throw, return the scale <= 0.
         policies::raise_evaluation_error<Dist::value_type>(function,
           "Computed scale (%1%) is <= 0!" " Was the complement intended?",
- result, policies::policy<>());
- }
+ result, policies::policy<>()); // This is only the default policy - also Want a version with Policy here.
+ }
+ return result;
+ } // template <class Dist, class Real1, class Real2, class Real3> typename Dist::value_type find_scale
 
- return result;
- }
   } // namespace boost
 } // namespace math
 

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-17 05:17:42 EDT (Mon, 17 Sep 2007)
@@ -22,6 +22,11 @@
 
 #include <utility>
 
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4127) // conditional expression is constant
+#endif
+
 namespace boost{ namespace math{
 
 template <class RealType = double, class Policy = policies::policy<> >
@@ -82,6 +87,7 @@
 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.
+
         using boost::math::tools::max_value;
         return std::pair<RealType, RealType>(-max_value<RealType>(), max_value<RealType>()); // - to + max value.
 }
@@ -103,11 +109,17 @@
 
    RealType result;
    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;
+ }
 
    RealType exponent = x - mean;
    exponent *= -exponent;
@@ -127,7 +139,15 @@
    RealType sd = dist.standard_deviation();
    RealType mean = dist.mean();
    static const char* function = "boost::math::cdf(const normal_distribution<%1%>&, %1%)";
-
+ RealType result;
+ if(false == detail::check_scale(function, sd, &result, Policy()))
+ {
+ return result;
+ }
+ if(false == detail::check_location(function, mean, &result, Policy()))
+ {
+ return result;
+ }
    if(std::numeric_limits<RealType>::has_infinity && x == std::numeric_limits<RealType>::infinity())
    { // cdf +infinity is unity.
      return 1;
@@ -136,20 +156,14 @@
    { // cdf -infinity is zero.
      return 0;
    }
-
- RealType result;
- 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;
-
+ {
+ return result;
+ }
    RealType diff = (x - mean) / (sd * constants::root_two<RealType>());
-
    result = boost::math::erfc(-diff, Policy()) / 2;
    return result;
-}
+} // cdf
 
 template <class RealType, class Policy>
 inline RealType quantile(const normal_distribution<RealType, Policy>& dist, const RealType& p)
@@ -173,7 +187,7 @@
    result *= sd * constants::root_two<RealType>();
    result += mean;
    return result;
-}
+} // quantile
 
 template <class RealType, class Policy>
 inline RealType cdf(const complemented2_type<normal_distribution<RealType, Policy>, RealType>& c)
@@ -186,11 +200,11 @@
    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.
+ { // cdf complement +infinity is zero.
      return 0;
    }
    if(std::numeric_limits<RealType>::has_infinity && x == -std::numeric_limits<RealType>::infinity())
- { // cdf -infinity is unity.
+ { // cdf complement -infinity is unity.
      return 1;
    }
    RealType result;
@@ -204,7 +218,7 @@
    RealType diff = (x - mean) / (sd * constants::root_two<RealType>());
    result = boost::math::erfc(diff, Policy()) / 2;
    return result;
-}
+} // cdf complement
 
 template <class RealType, class Policy>
 inline RealType quantile(const complemented2_type<normal_distribution<RealType, Policy>, RealType>& c)
@@ -213,22 +227,20 @@
 
    RealType sd = c.dist.standard_deviation();
    RealType mean = c.dist.mean();
- RealType q = c.param;
-
    static const char* function = "boost::math::quantile(const complement(normal_distribution<%1%>&), %1%)";
    RealType result;
    if(false == detail::check_scale(function, sd, &result, Policy()))
       return result;
    if(false == detail::check_location(function, mean, &result, Policy()))
       return result;
+ RealType q = c.param;
    if(false == detail::check_probability(function, q, &result, Policy()))
       return result;
- RealType r;
- r = boost::math::erfc_inv(2 * q, Policy());
- r *= sd * constants::root_two<RealType>();
- r += mean;
- return r;
-}
+ result = boost::math::erfc_inv(2 * q, Policy());
+ result *= sd * constants::root_two<RealType>();
+ result += mean;
+ return result;
+} // quantile
 
 template <class RealType, class Policy>
 inline RealType mean(const normal_distribution<RealType, Policy>& dist)
@@ -275,6 +287,10 @@
 } // namespace math
 } // namespace boost
 
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
 // This include must be at the end, *after* the accessors
 // for this distribution have been defined, in order to
 // keep compilers that support two-phase lookup happy.


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