]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/test/test_hermite.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / math / test / test_hermite.hpp
CommitLineData
7c673cae
FG
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#ifdef _MSC_VER
8# pragma warning(disable : 4127) // conditional expression is constant
9# pragma warning(disable : 4512) // assignment operator could not be generated
10# pragma warning(disable : 4756) // overflow in constant arithmetic
11// Constants are too big for float case, but this doesn't matter for test.
12#endif
13
14#include <boost/math/concepts/real_concept.hpp>
15#define BOOST_TEST_MAIN
16#include <boost/test/unit_test.hpp>
92f5a8d4 17#include <boost/test/tools/floating_point_comparison.hpp>
7c673cae
FG
18#include <boost/math/special_functions/math_fwd.hpp>
19#include <boost/math/constants/constants.hpp>
20#include <boost/array.hpp>
21#include "functor.hpp"
22
23#include "handle_test_result.hpp"
24#include "table_type.hpp"
25
26#ifndef SC_
27#define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
28#endif
29
30template <class Real, class T>
31void do_test_hermite(const T& data, const char* type_name, const char* test_name)
32{
33#if !(defined(ERROR_REPORTING_MODE) && !defined(HERMITE_FUNCTION_TO_TEST))
34 typedef Real value_type;
35
36 typedef value_type (*pg)(unsigned, value_type);
37#ifdef HERMITE_FUNCTION_TO_TEST
38 pg funcp = HERMITE_FUNCTION_TO_TEST;
39#elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
40 pg funcp = boost::math::hermite<value_type>;
41#else
42 pg funcp = boost::math::hermite;
43#endif
44
45 boost::math::tools::test_result<value_type> result;
46
47 std::cout << "Testing " << test_name << " with type " << type_name
48 << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
49
50 //
51 // test hermite against data:
52 //
53 result = boost::math::tools::test_hetero<Real>(
54 data,
55 bind_func_int1<Real>(funcp, 0, 1),
56 extract_result<Real>(2));
57 handle_test_result(result, data[result.worst()], result.worst(), type_name, "hermite", test_name);
58
59 std::cout << std::endl;
60#endif
61}
62
63template <class T>
64void test_hermite(T, const char* name)
65{
66 //
67 // The actual test data is rather verbose, so it's in a separate file
68 //
69 // The contents are as follows, each row of data contains
70 // three items, input value a, input value b and erf(a, b):
71 //
72# include "hermite.ipp"
73
74 do_test_hermite<T>(hermite, name, "Hermite Polynomials");
75}
76
77template <class T>
78void test_spots(T, const char* t)
79{
80 std::cout << "Testing basic sanity checks for type " << t << std::endl;
81 //
82 // basic sanity checks, tolerance is 100 epsilon:
83 // These spots were generated by MathCAD, precision is
84 // 14-16 digits.
85 //
86 T tolerance = (std::max)(boost::math::tools::epsilon<T>() * 100, static_cast<T>(1e-14));
87 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(0, static_cast<T>(1)), static_cast<T>(1.L), tolerance);
88 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1)), static_cast<T>(2.L), tolerance);
89 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(2)), static_cast<T>(4.L), tolerance);
90 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(10)), static_cast<T>(20), tolerance);
91 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(100)), static_cast<T>(200), tolerance);
92 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1e6)), static_cast<T>(2e6), tolerance);
93 if(std::numeric_limits<T>::max_exponent >= std::numeric_limits<double>::max_exponent)
94 {
95 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1e307)), static_cast<T>(2e307), tolerance);
96 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(99, static_cast<T>(100)), static_cast<T>(4.967223743011310E+227L), tolerance);
97 }
98 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(30)), static_cast<T>(5.896624628001300E+17L), tolerance);
99 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(1000)), static_cast<T>(1.023976960161280E+33L), tolerance);
100 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(10)), static_cast<T>(8.093278209760000E+12L), tolerance);
101 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(-10)), static_cast<T>(8.093278209760000E+12L), tolerance);
102 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-10)), static_cast<T>(-7.880000000000000E+3L), tolerance);
103 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-1000)), static_cast<T>(-7.999988000000000E+9L), tolerance);
104 BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-1000000)), static_cast<T>(-7.999999999988000E+18L), tolerance);
105}
106