test_airy.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright John Maddock 2012
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include <pch_light.hpp>
  6. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  7. #define BOOST_TEST_MAIN
  8. #include <boost/test/unit_test.hpp>
  9. #include <boost/test/tools/floating_point_comparison.hpp>
  10. #include <boost/math/special_functions/math_fwd.hpp>
  11. #include <boost/math/concepts/real_concept.hpp>
  12. #include <boost/array.hpp>
  13. #include <iostream>
  14. #include <iomanip>
  15. #ifdef _MSC_VER
  16. # pragma warning(disable : 4756 4127) // overflow in constant arithmetic
  17. // Constants are too big for float case, but this doesn't matter for test.
  18. #endif
  19. //
  20. // DESCRIPTION:
  21. // ~~~~~~~~~~~~
  22. //
  23. // This file tests the Airy functions.
  24. // These are basically just a few spot tests, since the underlying implementation
  25. // is the same as for the Bessel functions.
  26. //
  27. template <class T>
  28. void test_airy(T, const char* name)
  29. {
  30. std::cout << "Testing type " << name << std::endl;
  31. static const boost::array<boost::array<T, 5>, 8> data =
  32. {{
  33. // Values are x, Ai, Bi, Ai', Bi'.
  34. // Calculated from functions.wolfram.com.
  35. {{ 0, static_cast<T>(0.355028053887817239260063186004183176397979174199177240583327L), static_cast<T>(0.614926627446000735150922369093613553594728188648596505040879L), static_cast<T>(-0.258819403792806798405183560189203963479091138354934582210002L), static_cast<T>(0.448288357353826357914823710398828390866226799212262061082809L) }},
  36. {{ 2, static_cast<T>(0.0349241304232743791353220807918076097610602138975832071886699L), static_cast<T>(3.29809499997821471028060442522345242200397596340362078768292L), static_cast<T>(-0.0530903844336536317039991858787034912485609900458779926304030L), static_cast<T>(4.10068204993288988938203407917793529439024461377513711983771L) }},
  37. {{ 3.5, static_cast<T>(0.00258409878698963496327714478330027845019631096464789073425468L), static_cast<T>(33.0555067546114794142573129819217946861266278143724855010951L), static_cast<T>(-0.00500441396795258283203024967883836790716278377542974739809987L), static_cast<T>(59.1643195813609870345742121795224602529063343063320217229383L) }},
  38. {{ 30.5, static_cast<T>(2.04253461666926015963302258449952681287194929082634196439857e-50L), static_cast<T>(1.41092256201712698413071856671990267572381736486242769613348e48L), static_cast<T>(-1.12969466271996376602221721397236452019046628449363103927812e-49L), static_cast<T>(7.78046629440950280615411694840600772185863288897663300007879e48L) }},
  39. {{ -2, static_cast<T>(0.227407428201685575991924436037873799460772225417096716495790L), static_cast<T>(-0.412302587956398488083234054611461042034534834472404728823877L), static_cast<T>(0.618259020741691041406264291332475282915777945124146942159898L), static_cast<T>(0.278795166921169522685097569410983241403000593451631000239732L) }},
  40. {{ -3.5, static_cast<T>(-0.375533823140431911934396951580170239543268576378264063902563L), static_cast<T>(0.168939837481058611843442769540943269911562243926304070915824L), static_cast<T>(-0.343443433454048146287937374098698857094194220958713294264017L), static_cast<T>(-0.693116284907288801752443612670580462699702668014978495343697L) }},
  41. {{ -30.25, static_cast<T>(-0.236900428491559731119806902381433570300271552218956227857722L), static_cast<T>(0.0418614989839147441219283537268101850442118139150748075124111L), static_cast<T>(-0.232197332372689274917364138870840123428255785603863926579897L), static_cast<T>(-1.30261375952554697768880873095691151213006925411329957440342L) }},
  42. {{ -300.5, static_cast<T>(-0.117584304761702008955433457721670950077867326839023449546057L), static_cast<T>(0.0673518035440918806545676478730240310819758211028871823560384), static_cast<T>(-1.16763702262473888724431076711846459336993902544926162874376L), static_cast<T>(-2.03826035550300900666977975504950803669545593208969273694133L) }},
  43. }};
  44. T tol = boost::math::tools::epsilon<T>() * 800;
  45. for(unsigned i = 0; i < data.size(); ++i)
  46. {
  47. BOOST_CHECK_CLOSE_FRACTION(data[i][1], boost::math::airy_ai(data[i][0]), tol);
  48. if(boost::math::isfinite(data[i][2]))
  49. BOOST_CHECK_CLOSE_FRACTION(data[i][2], boost::math::airy_bi(data[i][0]), tol);
  50. BOOST_CHECK_CLOSE_FRACTION(data[i][3], boost::math::airy_ai_prime(data[i][0]), tol);
  51. if(boost::math::isfinite(data[i][4]))
  52. BOOST_CHECK_CLOSE_FRACTION(data[i][4], boost::math::airy_bi_prime(data[i][0]), tol);
  53. }
  54. }
  55. BOOST_AUTO_TEST_CASE( test_main )
  56. {
  57. #ifdef TEST_GSL
  58. gsl_set_error_handler_off();
  59. #endif
  60. BOOST_MATH_CONTROL_FP;
  61. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  62. test_airy(0.1F, "float");
  63. #endif
  64. test_airy(0.1, "double");
  65. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  66. test_airy(0.1L, "long double");
  67. test_airy(boost::math::concepts::real_concept(0), "real_concept");
  68. #else
  69. std::cout << "<note>The long double tests have been disabled on this platform "
  70. "either because the long double overloads of the usual math functions are "
  71. "not available at all, or because they are too inaccurate for these tests "
  72. "to pass.</note>" << std::endl;
  73. #endif
  74. }