2 * Copyright Nick Thompson, 2019
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)
8 #include "math_unit_test.hpp"
13 #include <boost/core/demangle.hpp>
14 #include <boost/math/special_functions/gegenbauer.hpp>
15 #ifdef BOOST_HAS_FLOAT128
16 #include <boost/multiprecision/float128.hpp>
17 using boost::multiprecision::float128;
21 using boost::math::gegenbauer;
22 using boost::math::gegenbauer_derivative;
27 std::mt19937 gen(323723);
28 std::uniform_real_distribution<Real> xdis(-1, +1);
29 std::uniform_real_distribution<Real> lambdadis(-0.5, 1);
31 for(unsigned n = 0; n < 50; ++n) {
36 Real lambda = lambdadis(gen);
38 CHECK_ULP_CLOSE(gegenbauer(n, lambda, -x), -gegenbauer(n, lambda, x), 0);
41 CHECK_ULP_CLOSE(gegenbauer(n, lambda, -x), gegenbauer(n, lambda, x), 0);
50 Real lambda = 1/Real(4);
51 auto c2 = [&](Real x) { return -lambda + 2*lambda*(1+lambda)*x*x; };
56 Real expected = c2(x);
57 Real computed = gegenbauer(2, lambda, x);
58 CHECK_ULP_CLOSE(expected, computed, 0);
66 Real lambda = 1/Real(4);
67 auto c3 = [&](Real x) { return lambda*(1+lambda)*x*(-2 + 4*(2+lambda)*x*x/3); };
72 Real expected = c3(x);
73 Real computed = gegenbauer(3, lambda, x);
74 CHECK_ULP_CLOSE(expected, computed, 4);
80 void test_derivative()
83 auto c3_prime = [&](Real x) { return 2*lambda*(lambda+1)*(-1 + 2*(lambda+2)*x*x); };
84 auto c3_double_prime = [&](Real x) { return 8*lambda*(lambda+1)*(lambda+2)*x; };
88 Real expected = c3_prime(x);
89 Real computed = gegenbauer_derivative(3, lambda, x, 1);
90 CHECK_ULP_CLOSE(expected, computed, 1);
92 expected = c3_double_prime(x);
93 computed = gegenbauer_derivative(3, lambda, x, 2);
94 CHECK_ULP_CLOSE(expected, computed, 1);
105 test_parity<float>();
106 test_parity<double>();
107 test_parity<long double>();
109 test_quadratic<float>();
110 test_quadratic<double>();
111 test_quadratic<long double>();
113 test_cubic<double>();
114 test_cubic<long double>();
116 test_derivative<float>();
117 test_derivative<double>();
118 test_derivative<long double>();
120 #ifdef BOOST_HAS_FLOAT128
121 test_quadratic<boost::multiprecision::float128>();
122 test_cubic<boost::multiprecision::float128>();
125 return boost::math::test::report_errors();