From c64e355e2fa7bf1aca2b752a11f1ec71fabe49ae Mon Sep 17 00:00:00 2001 From: "Paul A. Bristow" Date: Wed, 7 Feb 2007 16:17:37 +0000 Subject: [PATCH] Spurious warning zerodivide suppressed as agreed. [SVN r3651] --- .../detail/derived_accessors.hpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/boost/math/distributions/detail/derived_accessors.hpp b/include/boost/math/distributions/detail/derived_accessors.hpp index eeba33653..184b6ac4d 100644 --- a/include/boost/math/distributions/detail/derived_accessors.hpp +++ b/include/boost/math/distributions/detail/derived_accessors.hpp @@ -30,6 +30,12 @@ #include #include +#ifdef BOOST_MSVC +# pragma warning(push) +# pragma warning(disable: 4723) // potential divide by 0 +// Suppressing spurious warning in coefficient_of_variation +#endif + namespace boost{ namespace math{ template @@ -81,10 +87,11 @@ typename Distribution::value_type coefficient_of_variation(const Distribution& d typedef typename Distribution::value_type value_type; value_type m = mean(dist); value_type d = standard_deviation(dist); - if((m < 1) && (d > m * tools::max_value())) - return tools::overflow_error( - BOOST_CURRENT_FUNCTION); - return d / m; + if((abs(m) < 1) && (d > abs(m) * tools::max_value())) + { // Checks too that m is not zero, + return tools::overflow_error(BOOST_CURRENT_FUNCTION); + } + return d / m; // so MSVC warning on zerodivide is spurious, and suppressed. } // // Next follow overloads of some of the standard accessors with mixed @@ -149,4 +156,9 @@ typename Dist::value_type median(const Dist& d) } // namespace math } // namespace boost + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + #endif // BOOST_STATS_DERIVED_HPP