diff --git a/include/boost/math/special_functions/gamma.hpp b/include/boost/math/special_functions/gamma.hpp index c2f390713..7c37a0301 100644 --- a/include/boost/math/special_functions/gamma.hpp +++ b/include/boost/math/special_functions/gamma.hpp @@ -139,7 +139,7 @@ T gamma_imp(T z, const Policy& pol, const Lanczos& l) result = gamma_imp(T(-z), pol, l) * sinpx(z); BOOST_MATH_INSTRUMENT_VARIABLE(result); if((fabs(result) < 1) && (tools::max_value() * fabs(result) < boost::math::constants::pi())) - return policies::raise_overflow_error(function, "Result of tgamma is too large to represent.", pol); + return -boost::math::sign(result) * policies::raise_overflow_error(function, "Result of tgamma is too large to represent.", pol); result = -boost::math::constants::pi() / result; if(result == 0) return policies::raise_underflow_error(function, "Result of tgamma is too small to represent.", pol); @@ -178,13 +178,13 @@ T gamma_imp(T z, const Policy& pol, const Lanczos& l) // we're going to overflow unless this is done with care: BOOST_MATH_INSTRUMENT_VARIABLE(zgh); if(lzgh * z / 2 > tools::log_max_value()) - return policies::raise_overflow_error(function, "Result of tgamma is too large to represent.", pol); + return boost::math::sign(result) * policies::raise_overflow_error(function, "Result of tgamma is too large to represent.", pol); T hp = pow(zgh, (z / 2) - T(0.25)); BOOST_MATH_INSTRUMENT_VARIABLE(hp); result *= hp / exp(zgh); BOOST_MATH_INSTRUMENT_VARIABLE(result); if(tools::max_value() / hp < result) - return policies::raise_overflow_error(function, "Result of tgamma is too large to represent.", pol); + return boost::math::sign(result) * policies::raise_overflow_error(function, "Result of tgamma is too large to represent.", pol); result *= hp; BOOST_MATH_INSTRUMENT_VARIABLE(result); } diff --git a/test/test_gamma.hpp b/test/test_gamma.hpp index 26441ff29..d17ff76ce 100644 --- a/test/test_gamma.hpp +++ b/test/test_gamma.hpp @@ -167,6 +167,7 @@ void test_gamma(T, const char* name) template void test_spots(T) { + BOOST_MATH_STD_USING // // basic sanity checks, tolerance is 50 epsilon expressed as a percentage: //