// Copyright John Maddock 2005. // Copyright Paul A. Bristow 2010 // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include "functor.hpp" #include "handle_test_result.hpp" #include "table_type.hpp" template void do_test(const T& data, const char* type_name, const char* test_name) { typedef Real value_type; typedef value_type (*pg)(value_type); #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) pg funcp = &boost::math::log1p; #else pg funcp = &boost::math::log1p; #endif boost::math::tools::test_result result; std::cout << "Testing " << test_name << " with type " << type_name << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; // // test log1p against data: // #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) funcp = boost::math::log1p; #else funcp = &boost::math::log1p; #endif result = boost::math::tools::test_hetero( data, bind_func(funcp, 0), extract_result(1)); handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::log1p", "log1p and expm1"); std::cout << std::endl; // // test expm1 against data: // #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) funcp = boost::math::expm1; #else funcp = boost::math::expm1; #endif result = boost::math::tools::test_hetero( data, bind_func(funcp, 0), extract_result(2)); handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::expm1", "log1p and expm1"); std::cout << std::endl; } template void test(T, const char* type_name) { # include "log1p_expm1_data.ipp" do_test(log1p_expm1_data, type_name, "expm1 and log1p"); // // C99 Appendix F special cases: static const T zero = 0; static const T m_one = -1; BOOST_CHECK_EQUAL(boost::math::log1p(zero), zero); BOOST_CHECK_EQUAL(boost::math::log1p(T(-zero)), zero); BOOST_CHECK_EQUAL(boost::math::expm1(zero), zero); if(std::numeric_limits::has_infinity) { BOOST_CHECK_EQUAL(boost::math::log1p(m_one), -std::numeric_limits::infinity()); BOOST_CHECK_EQUAL(boost::math::expm1(T(-std::numeric_limits::infinity())), m_one); BOOST_CHECK_EQUAL(boost::math::expm1(std::numeric_limits::infinity()), std::numeric_limits::infinity()); #ifndef __BORLANDC__ // When building with Borland's compiler, simply the *presence* // of these tests cause other unrelated tests to fail!!! :-( using namespace boost::math::policies; typedef policy > pol; BOOST_CHECK_THROW(boost::math::log1p(m_one, pol()), std::overflow_error); BOOST_CHECK_THROW(boost::math::expm1(std::numeric_limits::infinity(), pol()), std::overflow_error); #endif } }