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)
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.
14 #include <boost/math/concepts/real_concept.hpp>
15 #define BOOST_TEST_MAIN
16 #include <boost/test/unit_test.hpp>
17 #include <boost/test/tools/floating_point_comparison.hpp>
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"
23 #include "handle_test_result.hpp"
24 #include "table_type.hpp"
27 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
30 template <class Real, class T>
31 void do_test_hermite(const T& data, const char* type_name, const char* test_name)
33 #if !(defined(ERROR_REPORTING_MODE) && !defined(HERMITE_FUNCTION_TO_TEST))
34 typedef Real value_type;
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>;
42 pg funcp = boost::math::hermite;
45 boost::math::tools::test_result<value_type> result;
47 std::cout << "Testing " << test_name << " with type " << type_name
48 << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
51 // test hermite against data:
53 result = boost::math::tools::test_hetero<Real>(
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);
59 std::cout << std::endl;
64 void test_hermite(T, const char* name)
67 // The actual test data is rather verbose, so it's in a separate file
69 // The contents are as follows, each row of data contains
70 // three items, input value a, input value b and erf(a, b):
72 # include "hermite.ipp"
74 do_test_hermite<T>(hermite, name, "Hermite Polynomials");
78 void test_spots(T, const char* t)
80 std::cout << "Testing basic sanity checks for type " << t << std::endl;
82 // basic sanity checks, tolerance is 100 epsilon:
83 // These spots were generated by MathCAD, precision is
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)
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);
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);