1 // Copyright John Maddock 2005.
2 // Copyright Paul A. Bristow 2010
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 #include <boost/array.hpp>
8 #include "functor.hpp"
9
10 #include "handle_test_result.hpp"
11 #include "table_type.hpp"
12
13
14 template <class Real, class T>
do_test(const T & data,const char * type_name,const char * test_name)15 void do_test(const T& data, const char* type_name, const char* test_name)
16 {
17 typedef Real value_type;
18
19 typedef value_type (*pg)(value_type);
20 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
21 pg funcp = &boost::math::log1p<value_type>;
22 #else
23 pg funcp = &boost::math::log1p;
24 #endif
25
26 boost::math::tools::test_result<value_type> result;
27 std::cout << "Testing " << test_name << " with type " << type_name
28 << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
29 //
30 // test log1p against data:
31 //
32 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
33 funcp = boost::math::log1p<value_type>;
34 #else
35 funcp = &boost::math::log1p;
36 #endif
37 result = boost::math::tools::test_hetero<Real>(
38 data,
39 bind_func<Real>(funcp, 0),
40 extract_result<Real>(1));
41 handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::log1p", "log1p and expm1");
42 std::cout << std::endl;
43 //
44 // test expm1 against data:
45 //
46 #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
47 funcp = boost::math::expm1<value_type>;
48 #else
49 funcp = boost::math::expm1;
50 #endif
51 result = boost::math::tools::test_hetero<Real>(
52 data,
53 bind_func<Real>(funcp, 0),
54 extract_result<Real>(2));
55 handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::expm1", "log1p and expm1");
56 std::cout << std::endl;
57 }
58
59 template <class T>
test(T,const char * type_name)60 void test(T, const char* type_name)
61 {
62 # include "log1p_expm1_data.ipp"
63
64 do_test<T>(log1p_expm1_data, type_name, "expm1 and log1p");
65
66 //
67 // C99 Appendix F special cases:
68 static const T zero = 0;
69 static const T m_one = -1;
70 BOOST_CHECK_EQUAL(boost::math::log1p(zero), zero);
71 BOOST_CHECK_EQUAL(boost::math::log1p(T(-zero)), zero);
72 BOOST_CHECK_EQUAL(boost::math::expm1(zero), zero);
73 if(std::numeric_limits<T>::has_infinity)
74 {
75 BOOST_CHECK_EQUAL(boost::math::log1p(m_one), -std::numeric_limits<T>::infinity());
76 BOOST_CHECK_EQUAL(boost::math::expm1(T(-std::numeric_limits<T>::infinity())), m_one);
77 BOOST_CHECK_EQUAL(boost::math::expm1(std::numeric_limits<T>::infinity()), std::numeric_limits<T>::infinity());
78 #ifndef __BORLANDC__
79 // When building with Borland's compiler, simply the *presence*
80 // of these tests cause other unrelated tests to fail!!! :-(
81 using namespace boost::math::policies;
82 typedef policy<overflow_error<throw_on_error> > pol;
83 BOOST_CHECK_THROW(boost::math::log1p(m_one, pol()), std::overflow_error);
84 BOOST_CHECK_THROW(boost::math::expm1(std::numeric_limits<T>::infinity(), pol()), std::overflow_error);
85 #endif
86 }
87 }
88
89