1 // Copyright John Maddock 2006.
2 // Copyright Paul A. Bristow 2007, 2009
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
9 #include <boost/math/special_functions/gamma.hpp>
10 #define BOOST_TEST_MAIN
11 #include <boost/test/unit_test.hpp>
12 #include <boost/test/floating_point_comparison.hpp>
13 #include <boost/math/tools/stats.hpp>
14 #include <boost/math/tools/test.hpp>
15 #include <boost/math/constants/constants.hpp>
16 #include <boost/type_traits/is_floating_point.hpp>
17 #include <boost/array.hpp>
18 #include "libs/math/test/functor.hpp"
20 #include "libs/math/test/handle_test_result.hpp"
21 #include "../table_type.hpp"
24 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
27 template <class Real, class T>
28 void do_test_gamma(const T& data, const char* type_name, const char* test_name)
30 typedef typename T::value_type row_type;
31 typedef Real value_type;
33 typedef value_type (*pg)(value_type);
34 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
35 pg funcp = boost::math::tgamma<value_type>;
37 pg funcp = boost::math::tgamma;
40 boost::math::tools::test_result<value_type> result;
42 std::cout << "Testing " << test_name << " with type " << type_name
43 << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
46 // test tgamma against data:
48 result = boost::math::tools::test_hetero<Real>(
50 bind_func<Real>(funcp, 0),
51 extract_result<Real>(1));
52 handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::tgamma", test_name);
55 // test lgamma against data:
57 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
58 funcp = boost::math::lgamma<value_type>;
60 funcp = boost::math::lgamma;
62 result = boost::math::tools::test_hetero<Real>(
64 bind_func<Real>(funcp, 0),
65 extract_result<Real>(2));
66 handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::lgamma", test_name);
68 std::cout << std::endl;
72 void test_gamma(T, const char* name)
76 do_test_gamma<T>(gamma, name, "random values");
78 # include "gamma_1_2.ipp"
80 do_test_gamma<T>(gamma_1_2, name, "Values near 1 and 2");
82 # include "gamma_0.ipp"
84 do_test_gamma<T>(gamma_0, name, "Values near 0");
86 # include "gamma_neg.ipp"
88 do_test_gamma<T>(gamma_neg, name, "Negative arguments");