]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/test_ibeta_derivative.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / math / test / test_ibeta_derivative.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 #include <boost/math/concepts/real_concept.hpp>
8 #define BOOST_TEST_MAIN
9 #include <boost/test/unit_test.hpp>
10 #include <boost/test/tools/floating_point_comparison.hpp>
11 #include <boost/math/special_functions/beta.hpp>
12 #include <boost/math/tools/stats.hpp>
13 #include <boost/math/tools/test.hpp>
14 #include <boost/math/constants/constants.hpp>
15 #include <boost/type_traits/is_floating_point.hpp>
16 #include <boost/array.hpp>
17 #include "functor.hpp"
18
19 #include "handle_test_result.hpp"
20 #include "table_type.hpp"
21
22 #ifndef SC_
23 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
24 #endif
25
26 template <class T>
27 T ibeta_forwarder(T a, T b, T x)
28 {
29 T derivative;
30 boost::math::detail::ibeta_imp(a, b, x, boost::math::policies::policy<>(), false, true, &derivative);
31 return derivative;
32 }
33
34 template <class Real, class T>
35 void do_test_beta(const T& data, const char* type_name, const char* test_name)
36 {
37 typedef Real value_type;
38
39 typedef value_type (*pg)(value_type, value_type, value_type);
40 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
41 pg funcp = boost::math::ibeta_derivative<value_type, value_type, value_type>;
42 #else
43 pg funcp = boost::math::ibeta_derivative;
44 #endif
45
46 boost::math::tools::test_result<value_type> result;
47
48 #if !(defined(ERROR_REPORTING_MODE) && !defined(BETA_INC_FUNCTION_TO_TEST))
49 std::cout << "Testing " << test_name << " with type " << type_name
50 << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
51
52 //
53 // test ibeta_derivative against data:
54 //
55 result = boost::math::tools::test_hetero<Real>(
56 data,
57 bind_func<Real>(funcp, 0, 1, 2),
58 extract_result<Real>(3));
59 handle_test_result(result, data[result.worst()], result.worst(), type_name, "beta (incomplete)", test_name);
60 #endif
61
62 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
63 funcp = ibeta_forwarder<value_type>;
64 #else
65 funcp = ibeta_forwarder;
66 #endif
67
68 if(boost::math::tools::digits<value_type>() > 40)
69 {
70 //
71 // test ibeta_derivative against data:
72 //
73 result = boost::math::tools::test_hetero<Real>(
74 data,
75 bind_func<Real>(funcp, 0, 1, 2),
76 extract_result<Real>(3));
77 handle_test_result(result, data[result.worst()], result.worst(), type_name, "beta (incomplete, internal call test)", test_name);
78 }
79 }
80
81 template <class T>
82 void test_beta(T, const char* name)
83 {
84 //
85 // The actual test data is rather verbose, so it's in a separate file
86 //
87 // The contents are as follows, each row of data contains
88 // five items, input value a, input value b, integration limits x, beta(a, b, x) and ibeta(a, b, x):
89 //
90 #if !defined(TEST_DATA) || (TEST_DATA == 1)
91 # include "ibeta_derivative_small_data.ipp"
92
93 do_test_beta<T>(ibeta_derivative_small_data, name, "Incomplete Beta Function Derivative: Small Values");
94 #endif
95
96 #if !defined(TEST_DATA) || (TEST_DATA == 2)
97 # include "ibeta_derivative_data.ipp"
98
99 do_test_beta<T>(ibeta_derivative_data, name, "Incomplete Beta Function Derivative: Medium Values");
100
101 #endif
102 #ifndef __SUNPRO_CC
103 #if !defined(TEST_DATA) || (TEST_DATA == 3)
104 # include "ibeta_derivative_large_data.ipp"
105
106 do_test_beta<T>(ibeta_derivative_large_data, name, "Incomplete Beta Function Derivative: Large and Diverse Values");
107 #endif
108 #endif
109 #if !defined(TEST_DATA) || (TEST_DATA == 4)
110 # include "ibeta_derivative_int_data.ipp"
111
112 do_test_beta<T>(ibeta_derivative_int_data, name, "Incomplete Beta Function Derivative: Small Integer Values");
113 #endif
114 }
115
116 template <class T>
117 void test_spots(T)
118 {
119 using std::ldexp;
120 T tolerance = boost::math::tools::epsilon<T>() * 40000;
121 BOOST_CHECK_CLOSE(
122 ::boost::math::ibeta_derivative(
123 static_cast<T>(2),
124 static_cast<T>(4),
125 ldexp(static_cast<T>(1), -557)),
126 static_cast<T>(4.23957586190238472641508753637420672781472122471791800210e-167L), tolerance * 4);
127 BOOST_CHECK_CLOSE(
128 ::boost::math::ibeta_derivative(
129 static_cast<T>(2),
130 static_cast<T>(4.5),
131 ldexp(static_cast<T>(1), -557)),
132 static_cast<T>(5.24647512910420109893867082626308082567071751558842352760e-167L), tolerance * 4);
133 }
134