diff --git a/include/boost/math/distributions/beta.hpp b/include/boost/math/distributions/beta.hpp index fef991a87..617bd9dc0 100644 --- a/include/boost/math/distributions/beta.hpp +++ b/include/boost/math/distributions/beta.hpp @@ -298,15 +298,21 @@ namespace boost template BOOST_MATH_GPU_ENABLED inline RealType mean(const beta_distribution& dist) { // Mean of beta distribution = np. - return dist.alpha() / (dist.alpha() + dist.beta()); + using promoted_real_type = policies::evaluation_t; + const auto a = static_cast(dist.alpha()); + const auto b = static_cast(dist.beta()); + + return static_cast(a / (a + b)); } // mean template BOOST_MATH_GPU_ENABLED inline RealType variance(const beta_distribution& dist) { // Variance of beta distribution = np(1-p). - RealType a = dist.alpha(); - RealType b = dist.beta(); - return (a * b) / ((a + b ) * (a + b) * (a + b + 1)); + using promoted_real_type = policies::evaluation_t; + const auto a = static_cast(dist.alpha()); + const auto b = static_cast(dist.beta()); + + return static_cast((a * b) / ((a + b ) * (a + b) * (a + b + 1))); } // variance template @@ -330,9 +336,11 @@ namespace boost "mode undefined for beta = %1%, must be > 1!", dist.beta(), Policy()); return result; } - RealType a = dist.alpha(); - RealType b = dist.beta(); - return (a-1) / (a + b - 2); + using promoted_real_type = policies::evaluation_t; + const auto a = static_cast(dist.alpha()); + const auto b = static_cast(dist.beta()); + + return static_cast((a-1) / (a + b - 2)); } // mode //template @@ -347,20 +355,23 @@ namespace boost BOOST_MATH_GPU_ENABLED inline RealType skewness(const beta_distribution& dist) { BOOST_MATH_STD_USING // ADL of std functions. - RealType a = dist.alpha(); - RealType b = dist.beta(); - return (2 * (b-a) * sqrt(a + b + 1)) / ((a + b + 2) * sqrt(a * b)); + using promoted_real_type = policies::evaluation_t; + const auto a = static_cast(dist.alpha()); + const auto b = static_cast(dist.beta()); + + return static_cast((2 * (b-a) * sqrt(a + b + 1)) / ((a + b + 2) * sqrt(a * b))); } // skewness template BOOST_MATH_GPU_ENABLED inline RealType kurtosis_excess(const beta_distribution& dist) { - RealType a = dist.alpha(); - RealType b = dist.beta(); - RealType a_2 = a * a; - RealType n = 6 * (a_2 * a - a_2 * (2 * b - 1) + b * b * (b + 1) - 2 * a * b * (b + 2)); - RealType d = a * b * (a + b + 2) * (a + b + 3); - return n / d; + using promoted_real_type = policies::evaluation_t; + const auto a = static_cast(dist.alpha()); + const auto b = static_cast(dist.beta()); + const promoted_real_type a_2 = a * a; + const promoted_real_type n = 6 * (a_2 * a - a_2 * (2 * b - 1) + b * b * (b + 1) - 2 * a * b * (b + 2)); + const promoted_real_type d = a * b * (a + b + 2) * (a + b + 3); + return static_cast(n / d); } // kurtosis_excess template @@ -398,7 +409,7 @@ namespace boost { if (a == 1) { - return static_cast(1 / beta(a, b)); + return static_cast(1 / beta(a, b, Policy())); } else if (a < 1) { @@ -413,7 +424,7 @@ namespace boost { if (b == 1) { - return static_cast(1 / beta(a, b)); + return static_cast(1 / beta(a, b, Policy())); } else if (b < 1) {