⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_legendre.cpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   typedef value_type (*pg)(int, value_type);#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)   pg funcp = boost::math::legendre_p<value_type>;#else   pg funcp = boost::math::legendre_p;#endif   boost::math::tools::test_result<value_type> result;   std::cout << "Testing " << test_name << " with type " << type_name      << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";   //   // test legendre_p against data:   //   result = boost::math::tools::test(      data,       bind_func_int1(funcp, 0, 1),       extract_result(2));   handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::legendre_p", test_name);#ifdef TEST_OTHER   if(::boost::is_floating_point<value_type>::value){      funcp = other::legendre_p;   result = boost::math::tools::test(      data,       bind_func_int1(funcp, 0, 1),       extract_result(2));      print_test_result(result, data[result.worst()], result.worst(), type_name, "other::legendre_p");   }#endif   typedef value_type (*pg2)(unsigned, value_type);#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)   pg2 funcp2 = boost::math::legendre_q<value_type>;#else   pg2 funcp2 = boost::math::legendre_q;#endif   //   // test legendre_q against data:   //   result = boost::math::tools::test(      data,       bind_func_int1(funcp2, 0, 1),       extract_result(3));   handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::legendre_q", test_name);#ifdef TEST_OTHER   if(::boost::is_floating_point<value_type>::value){      funcp = other::legendre_q;   result = boost::math::tools::test(      data,       bind_func_int1(funcp2, 0, 1),       extract_result(3));      print_test_result(result, data[result.worst()], result.worst(), type_name, "other::legendre_q");   }#endif   std::cout << std::endl;}template <class T>void do_test_assoc_legendre_p(const T& data, const char* type_name, const char* test_name){   typedef typename T::value_type row_type;   typedef typename row_type::value_type value_type;   typedef value_type (*pg)(int, int, value_type);#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)   pg funcp = boost::math::legendre_p<value_type>;#else   pg funcp = boost::math::legendre_p;#endif   boost::math::tools::test_result<value_type> result;   std::cout << "Testing " << test_name << " with type " << type_name      << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";   //   // test legendre_p against data:   //   result = boost::math::tools::test(      data,       bind_func_int2(funcp, 0, 1, 2),       extract_result(3));   handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::legendre_p", test_name);   std::cout << std::endl;}template <class T>void test_legendre_p(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 a, input value b and erf(a, b):   // #  include "legendre_p.ipp"   do_test_legendre_p(legendre_p, name, "Legendre Polynomials: Small Values");#  include "legendre_p_large.ipp"   do_test_legendre_p(legendre_p_large, name, "Legendre Polynomials: Large Values");#  include "assoc_legendre_p.ipp"   do_test_assoc_legendre_p(assoc_legendre_p, name, "Associated Legendre Polynomials: Small Values");}template <class T>void test_spots(T, const char* t){   std::cout << "Testing basic sanity checks for type " << t << std::endl;   //   // basic sanity checks, tolerance is 100 epsilon:   //   T tolerance = boost::math::tools::epsilon<T>() * 100;   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(1, static_cast<T>(0.5L)), static_cast<T>(0.5L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-1, static_cast<T>(0.5L)), static_cast<T>(1L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, static_cast<T>(0.5L)), static_cast<T>(-0.2890625000000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, static_cast<T>(0.5L)), static_cast<T>(-0.4375000000000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, static_cast<T>(0.5L)), static_cast<T>(0.2231445312500000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, static_cast<T>(0.5L)), static_cast<T>(0.3232421875000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, static_cast<T>(0.5L)), static_cast<T>(-0.09542943523261546936538467572384923220258L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, static_cast<T>(0.5L)), static_cast<T>(-0.1316993126940266257030910566308990611306L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, 2, static_cast<T>(0.5L)), static_cast<T>(4.218750000000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast<T>(0.5L)), static_cast<T>(5.625000000000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast<T>(0.5L)), static_cast<T>(-5696.789530152175143607977274672800795328L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast<T>(0.5L)), static_cast<T>(465.1171875000000000000000000000000000000L), tolerance);   if(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent)   {      BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast<T>(0.5L)), static_cast<T>(-7.855722083232252643913331343916012143461e45L), tolerance);   }   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, 20, static_cast<T>(0.5L)), static_cast<T>(4.966634149702370788037088925152355134665e30L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, 2, static_cast<T>(-0.5L)), static_cast<T>(4.218750000000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast<T>(-0.5L)), static_cast<T>(-5.625000000000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast<T>(-0.5L)), static_cast<T>(-5696.789530152175143607977274672800795328L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast<T>(-0.5L)), static_cast<T>(465.1171875000000000000000000000000000000L), tolerance);   if(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent)   {      BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast<T>(-0.5L)), static_cast<T>(-7.855722083232252643913331343916012143461e45L), tolerance);   }   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, 20, static_cast<T>(-0.5L)), static_cast<T>(-4.966634149702370788037088925152355134665e30L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, -2, static_cast<T>(0.5L)), static_cast<T>(0.01171875000000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, -2, static_cast<T>(0.5L)), static_cast<T>(0.04687500000000000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, -5, static_cast<T>(0.5L)), static_cast<T>(0.00002378609812640364935569308025139290054701L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, -4, static_cast<T>(0.5L)), static_cast<T>(0.0002563476562500000000000000000000000000000L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, -30, static_cast<T>(0.5L)), static_cast<T>(-2.379819988646847616996471299410611801239e-48L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, -20, static_cast<T>(0.5L)), static_cast<T>(4.356454600748202401657099008867502679122e-33L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(1, static_cast<T>(0.5L)), static_cast<T>(-0.7253469278329725771511886907693685738381L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(4, static_cast<T>(0.5L)), static_cast<T>(0.4401745259867706044988642951843745400835L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(7, static_cast<T>(0.5L)), static_cast<T>(-0.3439152932669753451878700644212067616780L), tolerance);   BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(40, static_cast<T>(0.5L)), static_cast<T>(0.1493671665503550095010454949479907886011L), tolerance);}int test_main(int, char* []){   BOOST_MATH_CONTROL_FP;   test_spots(0.0F, "float");   test_spots(0.0, "double");#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS   test_spots(0.0L, "long double");   test_spots(boost::math::concepts::real_concept(0.1), "real_concept");#endif   expected_results();   test_legendre_p(0.1F, "float");   test_legendre_p(0.1, "double");#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS   test_legendre_p(0.1L, "long double");#ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS   test_legendre_p(boost::math::concepts::real_concept(0.1), "real_concept");#endif#else   std::cout << "<note>The long double tests have been disabled on this platform "      "either because the long double overloads of the usual math functions are "      "not available at all, or because they are too inaccurate for these tests "      "to pass.</note>" << std::cout;#endif   return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -