1 // Copyright John Maddock 2014.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/math/concepts/real_concept.hpp>
7 #define BOOST_TEST_MAIN
8 #include <boost/test/unit_test.hpp>
9 #include <boost/test/floating_point_comparison.hpp>
10 #include <boost/math/special_functions/math_fwd.hpp>
11 #include <boost/math/constants/constants.hpp>
12 #include <boost/type_traits/is_floating_point.hpp>
13 #include <boost/array.hpp>
14 #include "functor.hpp"
16 #include "handle_test_result.hpp"
17 #include "table_type.hpp"
20 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
23 template <class Real, class T>
24 void do_test_trig(const T& data, const char* type_name, const char* test_name)
26 #if !(defined(ERROR_REPORTING_MODE) && !defined(SIN_PI_RATIO_FUNCTION_TO_TEST))
27 typedef Real value_type;
29 typedef value_type (*pg)(value_type);
30 #ifdef SIN_PI_RATIO_FUNCTION_TO_TEST
31 pg funcp = SIN_PI_RATIO_FUNCTION_TO_TEST;
32 #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
33 pg funcp = boost::math::sin_pi<value_type>;
35 pg funcp = boost::math::sin_pi;
38 boost::math::tools::test_result<value_type> result;
40 std::cout << "Testing " << test_name << " with type " << type_name
41 << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
44 // test sin_pi against data:
46 result = boost::math::tools::test_hetero<Real>(
48 bind_func<Real>(funcp, 0),
49 extract_result<Real>(1));
50 handle_test_result(result, data[result.worst()], result.worst(), type_name, "sin_pi", test_name);
52 // test cos_pi against data:
54 #ifdef COS_PI_RATIO_FUNCTION_TO_TEST
55 funcp = COS_PI_RATIO_FUNCTION_TO_TEST;
56 #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
57 funcp = boost::math::cos_pi<value_type>;
59 funcp = boost::math::cos_pi;
61 result = boost::math::tools::test_hetero<Real>(
63 bind_func<Real>(funcp, 0),
64 extract_result<Real>(2));
65 handle_test_result(result, data[result.worst()], result.worst(), type_name, "cos_pi", test_name);
66 std::cout << std::endl;
71 void test_trig(T, const char* name)
74 // The actual test data is rather verbose, so it's in a separate file
76 // The contents are as follows, each row of data contains
77 // three items, input value a, input value b and erf(a, b):
79 # include "trig_data.ipp"
81 do_test_trig<T>(trig_data, name, "sin_pi and cos_pi");
83 # include "trig_data2.ipp"
85 do_test_trig<T>(trig_data2, name, "sin_pi and cos_pi near integers and half integers");