]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/test/log1p_expm1_test.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / math / test / log1p_expm1_test.hpp
CommitLineData
7c673cae
FG
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
14template <class Real, class T>
15void 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#ifdef LOG1P_FUNCTION_TO_TEST
21 pg funcp = LOG1P_FUNCTION_TO_TEST;
22#elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
23 pg funcp = &boost::math::log1p<value_type>;
24#else
25 pg funcp = &boost::math::log1p;
26#endif
27
28 boost::math::tools::test_result<value_type> result;
29 std::cout << "Testing " << test_name << " with type " << type_name
30 << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
31 //
32 // test log1p against data:
33 //
34#if !(defined(ERROR_REPORTING_MODE) && !defined(LOG1P_FUNCTION_TO_TEST))
35 result = boost::math::tools::test_hetero<Real>(
36 data,
37 bind_func<Real>(funcp, 0),
38 extract_result<Real>(1));
39 handle_test_result(result, data[result.worst()], result.worst(), type_name, "log1p", "Random test data");
40 std::cout << std::endl;
41#endif
42#if !(defined(ERROR_REPORTING_MODE) && !defined(EXPM1_FUNCTION_TO_TEST))
43 //
44 // test expm1 against data:
45 //
46#ifdef EXPM1_FUNCTION_TO_TEST
47 funcp = EXPM1_FUNCTION_TO_TEST;
48#elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
49 funcp = boost::math::expm1<value_type>;
50#else
51 funcp = boost::math::expm1;
52#endif
53 result = boost::math::tools::test_hetero<Real>(
54 data,
55 bind_func<Real>(funcp, 0),
56 extract_result<Real>(2));
57 handle_test_result(result, data[result.worst()], result.worst(), type_name, "expm1", "Random test data");
58 std::cout << std::endl;
59#endif
60}
61
62template <class T>
63void test(T, const char* type_name)
64{
65# include "log1p_expm1_data.ipp"
66
67 do_test<T>(log1p_expm1_data, type_name, "expm1 and log1p");
68
69 //
70 // C99 Appendix F special cases:
71 static const T zero = 0;
72 static const T m_one = -1;
73 BOOST_CHECK_EQUAL(boost::math::log1p(zero), zero);
74 BOOST_CHECK_EQUAL(boost::math::log1p(T(-zero)), zero);
75 BOOST_CHECK_EQUAL(boost::math::expm1(zero), zero);
76 if(std::numeric_limits<T>::has_infinity)
77 {
78 BOOST_CHECK_EQUAL(boost::math::log1p(m_one), -std::numeric_limits<T>::infinity());
79 BOOST_CHECK_EQUAL(boost::math::expm1(T(-std::numeric_limits<T>::infinity())), m_one);
80 BOOST_CHECK_EQUAL(boost::math::expm1(std::numeric_limits<T>::infinity()), std::numeric_limits<T>::infinity());
20effc67 81#ifndef BOOST_BORLANDC
7c673cae
FG
82#ifndef BOOST_NO_EXCEPTIONS
83 // When building with Borland's compiler, simply the *presence*
84 // of these tests cause other unrelated tests to fail!!! :-(
85 using namespace boost::math::policies;
86 typedef policy<overflow_error<throw_on_error> > pol;
87 BOOST_MATH_CHECK_THROW(boost::math::log1p(m_one, pol()), std::overflow_error);
88 BOOST_MATH_CHECK_THROW(boost::math::expm1(std::numeric_limits<T>::infinity(), pol()), std::overflow_error);
89#endif
90#endif
91 }
92}
93