// Copyright John Maddock 2006. // Copyright Paul A. Bristow 2007, 2009 // 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) #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error #define BOOST_TEST_MAIN #include #include #include #include #include #include #include #include #include "functor.hpp" #include "handle_test_result.hpp" #include "table_type.hpp" #ifndef SC_ #define SC_(x) static_cast::type>(BOOST_STRINGIZE(x)) #endif template void do_test_gamma(const T& data, const char* type_name, const char* test_name) { #if !(defined(ERROR_REPORTING_MODE) && (!defined(TGAMMA_FUNCTION_TO_TEST) || !defined(LGAMMA_FUNCTION_TO_TEST))) typedef Real value_type; typedef value_type (*pg)(value_type); #ifdef TGAMMA_FUNCTION_TO_TEST pg funcp = TGAMMA_FUNCTION_TO_TEST; #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) pg funcp = boost::math::tgamma; #else pg funcp = boost::math::tgamma; #endif boost::math::tools::test_result result; std::cout << "Testing " << test_name << " with type " << type_name << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; // // test tgamma against data: // 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, "tgamma", test_name); // // test lgamma against data: // #ifdef LGAMMA_FUNCTION_TO_TEST funcp = LGAMMA_FUNCTION_TO_TEST; #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) funcp = boost::math::lgamma; #else funcp = boost::math::lgamma; #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, "lgamma", test_name); std::cout << std::endl; #endif } template void test_gamma(T, const char* name) { // // The actual test data is rather verbose, so it's in a separate file // // The contents are as follows, each row of data contains // three items, input value, gamma and lgamma: // // gamma and lgamma at integer and half integer values: // boost::array, N> factorials; // // gamma and lgamma for z near 0: // boost::array, N> near_0; // // gamma and lgamma for z near 1: // boost::array, N> near_1; // // gamma and lgamma for z near 2: // boost::array, N> near_2; // // gamma and lgamma for z near -10: // boost::array, N> near_m10; // // gamma and lgamma for z near -55: // boost::array, N> near_m55; // // The last two cases are chosen more or less at random, // except that one is even and the other odd, and both are // at negative poles. The data near zero also tests near // a pole, the data near 1 and 2 are to probe lgamma as // the result -> 0. // # include "tgamma_mp_data.hpp" do_test_gamma(factorials, name, "factorials"); do_test_gamma(near_0, name, "near 0"); do_test_gamma(near_1, name, "near 1"); do_test_gamma(near_2, name, "near 2"); do_test_gamma(near_m10, name, "near -10"); do_test_gamma(near_m55, name, "near -55"); } void expected_results() { // // Define the max and mean errors expected for // various compilers and platforms. // add_expected_result( ".*", // compiler ".*", // stdlib ".*", // platform "number >", // test type(s) ".*", // test data group "lgamma", 9000, 4000); // test function add_expected_result( ".*", // compiler ".*", // stdlib ".*", // platform "number >", // test type(s) ".*", // test data group "lgamma", 60000, 20000); // test function add_expected_result( ".*", // compiler ".*", // stdlib ".*", // platform "cpp_bin_float_100|number >", // test type(s) ".*", // test data group "lgamma", 600000, 300000); // test function add_expected_result( ".*", // compiler ".*", // stdlib ".*", // platform ".*", // test type(s) ".*", // test data group "lgamma", 4800, 2500); // test function add_expected_result( ".*", // compiler ".*", // stdlib ".*", // platform ".*", // test type(s) ".*", // test data group "[tl]gamma", 100, 50); // test function // // Finish off by printing out the compiler/stdlib/platform names, // we do this to make it easier to mark up expected error rates. // std::cout << "Tests run with " << BOOST_COMPILER << ", " << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl; } BOOST_AUTO_TEST_CASE(test_main) { expected_results(); using namespace boost::multiprecision; test_gamma(number >(0), "number >"); test_gamma(number >(0), "number >"); test_gamma(cpp_bin_float_50(0), "cpp_bin_float_50"); test_gamma(number >(0), "number >"); test_gamma(number >(0), "number >"); test_gamma(number >(0), "number >"); test_gamma(number >(0), "number >"); test_gamma(cpp_bin_float_100(0), "cpp_bin_float_100"); }