// (C) Copyright Kilian Kilger 2025. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #define BOOST_TEST_MAIN #include #include #include #include #include #include using namespace std; using namespace boost::math; using namespace boost::math::policies; using namespace boost::multiprecision; typedef policy< policies::domain_error, policies::pole_error, policies::overflow_error, policies::evaluation_error > c_policy; template struct test_lower { T operator()(T a, T x) const { return tgamma_lower(a, x, c_policy()); } T expected(T a) const { return T(0.0); } }; template struct test_upper { T operator()(T a, T x) const { return tgamma(a, x, c_policy()); } T expected(T a) const { return tgamma(a, c_policy()); } }; template struct test_gamma_p { T operator()(T a, T x) const { return gamma_p(a, x, c_policy()); } T expected(T) const { return T(0.0); } }; template struct test_gamma_q { T operator()(T a, T x) const { return gamma_q(a, x, c_policy()); } T expected(T) const { return T(1.0); } }; template class Fun> void test_impl(T a) { Fun fn; errno = 0; T x = T(0.0); T result = fn(a, x); int saveErrno = errno; errno = 0; T expected = fn.expected(a); BOOST_CHECK(errno == saveErrno); BOOST_CHECK_EQUAL(result, expected); } template class Fun, typename T> void test_type_dispatch(T val) { if (val <= (std::numeric_limits::max)()) test_impl(static_cast(val)); if (val <= (std::numeric_limits::max)()) test_impl(static_cast(val)); #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_impl(static_cast(val)); #endif test_impl(static_cast(val)); } template class Fun> void test_impl() { test_type_dispatch(1.0); test_type_dispatch(0.1); test_type_dispatch(0.5); test_type_dispatch(0.6); test_type_dispatch(1.3); test_type_dispatch(1.5); test_type_dispatch(2); test_type_dispatch(100); test_type_dispatch((std::numeric_limits::max)()); test_type_dispatch((std::numeric_limits::max)()); #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_type_dispatch((std::numeric_limits::max)()); #endif } void test_derivative() { using namespace boost::math::detail; double derivative = 0; double result = gamma_incomplete_imp(1.0, 0.0, true, false, c_policy(), &derivative); BOOST_CHECK(errno == 0); BOOST_CHECK_EQUAL(derivative, tools::max_value() / 2); BOOST_CHECK_EQUAL(result, 0); } BOOST_AUTO_TEST_CASE( test_main ) { test_impl(); test_impl(); test_impl(); test_impl(); test_derivative(); }