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)
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/tools/stats.hpp>
12 #include <boost/math/tools/test.hpp>
13 #include <boost/type_traits/is_floating_point.hpp>
14 #include <boost/array.hpp>
15 #include <boost/math/special_functions/math_fwd.hpp>
16 #include "functor.hpp"
18 #include "handle_test_result.hpp"
19 #include "table_type.hpp"
22 #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
31 Real operator()(const S& row)
33 return boost::math::cbrt(Real(-Real(row[1])));
38 template <class Real, class T>
39 void do_test_cbrt(const T& data, const char* type_name, const char* test_name)
41 #if !(defined(ERROR_REPORTING_MODE) && !defined(CBRT_FUNCTION_TO_TEST))
42 typedef Real value_type;
44 typedef value_type (*pg)(value_type);
45 #ifdef CBRT_FUNCTION_TO_TEST
46 pg funcp = boost::math::cbrt<value_type>;
47 #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
48 pg funcp = boost::math::cbrt<value_type>;
50 pg funcp = boost::math::cbrt;
53 boost::math::tools::test_result<value_type> result;
55 std::cout << "Testing " << test_name << " with type " << type_name
56 << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
59 // test cbrt against data:
61 result = boost::math::tools::test_hetero<Real>(
63 bind_func<Real>(funcp, 1),
64 extract_result<Real>(0));
65 result += boost::math::tools::test_hetero<Real>(
67 negative_cbrt<Real>(),
68 negate<Real>(extract_result<Real>(0)));
69 handle_test_result(result, data[result.worst()], result.worst(), type_name, "cbrt", test_name);
70 std::cout << std::endl;
74 void test_cbrt(T, const char* name)
77 // The actual test data is rather verbose, so it's in a separate file.
79 // The contents are as follows, each row of data contains
80 // three items, input value a, input value b and erf(a, b):
82 # include "cbrt_data.ipp"
84 do_test_cbrt<T>(cbrt_data, name, "cbrt Function");