From 6b580bd6f18d485b9656d6918cfbca1e929c123e Mon Sep 17 00:00:00 2001 From: Nicholas McKibben Date: Sat, 4 Feb 2023 22:43:51 -0700 Subject: [PATCH] FIX: avoid overflow on overflow check in gamma_p_derivative_imp --- include/boost/math/special_functions/gamma.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/math/special_functions/gamma.hpp b/include/boost/math/special_functions/gamma.hpp index 68afe66e30..efd9eef713 100644 --- a/include/boost/math/special_functions/gamma.hpp +++ b/include/boost/math/special_functions/gamma.hpp @@ -1795,7 +1795,8 @@ T gamma_p_derivative_imp(T a, T x, const Policy& pol) // typedef typename lanczos::lanczos::type lanczos_type; T f1 = detail::regularised_gamma_prefix(a, x, pol, lanczos_type()); - if((x < 1) && (tools::max_value() * x < f1)) + static const T inv_max_value = 1.0 / tools::max_value(); + if((x < 1) && (x < inv_max_value * f1)) { // overflow: return policies::raise_overflow_error("boost::math::gamma_p_derivative<%1%>(%1%, %1%)", nullptr, pol);