Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / multiprecision / test / math / high_prec / test_gamma.hpp
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)
6
7 #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
8
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"
19
20 #include "libs/math/test/handle_test_result.hpp"
21 #include "../table_type.hpp"
22
23 #ifndef SC_
24 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
25 #endif
26
27 template <class Real, class T>
28 void do_test_gamma(const T& data, const char* type_name, const char* test_name)
29 {
30    typedef typename T::value_type row_type;
31    typedef Real                   value_type;
32
33    typedef value_type (*pg)(value_type);
34 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
35    pg funcp = boost::math::tgamma<value_type>;
36 #else
37    pg funcp = boost::math::tgamma;
38 #endif
39
40    boost::math::tools::test_result<value_type> result;
41
42    std::cout << "Testing " << test_name << " with type " << type_name
43              << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
44
45    //
46    // test tgamma against data:
47    //
48    result = boost::math::tools::test_hetero<Real>(
49        data,
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);
53
54    //
55    // test lgamma against data:
56    //
57 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
58    funcp = boost::math::lgamma<value_type>;
59 #else
60    funcp    = boost::math::lgamma;
61 #endif
62    result = boost::math::tools::test_hetero<Real>(
63        data,
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);
67
68    std::cout << std::endl;
69 }
70
71 template <class T>
72 void test_gamma(T, const char* name)
73 {
74 #include "gamma.ipp"
75
76    do_test_gamma<T>(gamma, name, "random values");
77
78 #include "gamma_1_2.ipp"
79
80    do_test_gamma<T>(gamma_1_2, name, "Values near 1 and 2");
81
82 #include "gamma_0.ipp"
83
84    do_test_gamma<T>(gamma_0, name, "Values near 0");
85
86 #include "gamma_neg.ipp"
87
88    do_test_gamma<T>(gamma_neg, name, "Negative arguments");
89 }