bessel.hpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. // Copyright (c) 2007, 2013 John Maddock
  2. // Copyright Christopher Kormanyos 2013.
  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. // This header just defines the function entry points, and adds dispatch
  8. // to the right implementation method. Most of the implementation details
  9. // are in separate headers and copyright Xiaogang Zhang.
  10. //
  11. #ifndef BOOST_MATH_BESSEL_HPP
  12. #define BOOST_MATH_BESSEL_HPP
  13. #ifdef _MSC_VER
  14. # pragma once
  15. #endif
  16. #include <limits>
  17. #include <boost/math/special_functions/math_fwd.hpp>
  18. #include <boost/math/special_functions/detail/bessel_jy.hpp>
  19. #include <boost/math/special_functions/detail/bessel_jn.hpp>
  20. #include <boost/math/special_functions/detail/bessel_yn.hpp>
  21. #include <boost/math/special_functions/detail/bessel_jy_zero.hpp>
  22. #include <boost/math/special_functions/detail/bessel_ik.hpp>
  23. #include <boost/math/special_functions/detail/bessel_i0.hpp>
  24. #include <boost/math/special_functions/detail/bessel_i1.hpp>
  25. #include <boost/math/special_functions/detail/bessel_kn.hpp>
  26. #include <boost/math/special_functions/detail/iconv.hpp>
  27. #include <boost/math/special_functions/sin_pi.hpp>
  28. #include <boost/math/special_functions/cos_pi.hpp>
  29. #include <boost/math/special_functions/sinc.hpp>
  30. #include <boost/math/special_functions/trunc.hpp>
  31. #include <boost/math/special_functions/round.hpp>
  32. #include <boost/math/tools/rational.hpp>
  33. #include <boost/math/tools/promotion.hpp>
  34. #include <boost/math/tools/series.hpp>
  35. #include <boost/math/tools/roots.hpp>
  36. #ifdef _MSC_VER
  37. # pragma warning(push)
  38. # pragma warning(disable: 6326) // potential comparison of a constant with another constant
  39. #endif
  40. namespace boost{ namespace math{
  41. namespace detail{
  42. template <class T, class Policy>
  43. struct sph_bessel_j_small_z_series_term
  44. {
  45. typedef T result_type;
  46. sph_bessel_j_small_z_series_term(unsigned v_, T x)
  47. : N(0), v(v_)
  48. {
  49. BOOST_MATH_STD_USING
  50. mult = x / 2;
  51. if(v + 3 > max_factorial<T>::value)
  52. {
  53. term = v * log(mult) - boost::math::lgamma(v+1+T(0.5f), Policy());
  54. term = exp(term);
  55. }
  56. else
  57. term = pow(mult, T(v)) / boost::math::tgamma(v+1+T(0.5f), Policy());
  58. mult *= -mult;
  59. }
  60. T operator()()
  61. {
  62. T r = term;
  63. ++N;
  64. term *= mult / (N * T(N + v + 0.5f));
  65. return r;
  66. }
  67. private:
  68. unsigned N;
  69. unsigned v;
  70. T mult;
  71. T term;
  72. };
  73. template <class T, class Policy>
  74. inline T sph_bessel_j_small_z_series(unsigned v, T x, const Policy& pol)
  75. {
  76. BOOST_MATH_STD_USING // ADL of std names
  77. sph_bessel_j_small_z_series_term<T, Policy> s(v, x);
  78. std::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
  79. T result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter);
  80. policies::check_series_iterations<T>("boost::math::sph_bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol);
  81. return result * sqrt(constants::pi<T>() / 4);
  82. }
  83. template <class T, class Policy>
  84. T cyl_bessel_j_imp(T v, T x, const bessel_no_int_tag& t, const Policy& pol)
  85. {
  86. BOOST_MATH_STD_USING
  87. static const char* function = "boost::math::bessel_j<%1%>(%1%,%1%)";
  88. if(x < 0)
  89. {
  90. // better have integer v:
  91. if(floor(v) == v)
  92. {
  93. T r = cyl_bessel_j_imp(v, T(-x), t, pol);
  94. if(iround(v, pol) & 1)
  95. r = -r;
  96. return r;
  97. }
  98. else
  99. return policies::raise_domain_error<T>(
  100. function,
  101. "Got x = %1%, but we need x >= 0", x, pol);
  102. }
  103. T j, y;
  104. bessel_jy(v, x, &j, &y, need_j, pol);
  105. return j;
  106. }
  107. template <class T, class Policy>
  108. inline T cyl_bessel_j_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol)
  109. {
  110. BOOST_MATH_STD_USING // ADL of std names.
  111. int ival = detail::iconv(v, pol);
  112. // If v is an integer, use the integer recursion
  113. // method, both that and Steeds method are O(v):
  114. if((0 == v - ival))
  115. {
  116. return bessel_jn(ival, x, pol);
  117. }
  118. return cyl_bessel_j_imp(v, x, bessel_no_int_tag(), pol);
  119. }
  120. template <class T, class Policy>
  121. inline T cyl_bessel_j_imp(int v, T x, const bessel_int_tag&, const Policy& pol)
  122. {
  123. BOOST_MATH_STD_USING
  124. return bessel_jn(v, x, pol);
  125. }
  126. template <class T, class Policy>
  127. inline T sph_bessel_j_imp(unsigned n, T x, const Policy& pol)
  128. {
  129. BOOST_MATH_STD_USING // ADL of std names
  130. if(x < 0)
  131. return policies::raise_domain_error<T>(
  132. "boost::math::sph_bessel_j<%1%>(%1%,%1%)",
  133. "Got x = %1%, but function requires x > 0.", x, pol);
  134. //
  135. // Special case, n == 0 resolves down to the sinus cardinal of x:
  136. //
  137. if(n == 0)
  138. return boost::math::sinc_pi(x, pol);
  139. //
  140. // Special case for x == 0:
  141. //
  142. if(x == 0)
  143. return 0;
  144. //
  145. // When x is small we may end up with 0/0, use series evaluation
  146. // instead, especially as it converges rapidly:
  147. //
  148. if(x < 1)
  149. return sph_bessel_j_small_z_series(n, x, pol);
  150. //
  151. // Default case is just a naive evaluation of the definition:
  152. //
  153. return sqrt(constants::pi<T>() / (2 * x))
  154. * cyl_bessel_j_imp(T(T(n)+T(0.5f)), x, bessel_no_int_tag(), pol);
  155. }
  156. template <class T, class Policy>
  157. T cyl_bessel_i_imp(T v, T x, const Policy& pol)
  158. {
  159. //
  160. // This handles all the bessel I functions, note that we don't optimise
  161. // for integer v, other than the v = 0 or 1 special cases, as Millers
  162. // algorithm is at least as inefficient as the general case (the general
  163. // case has better error handling too).
  164. //
  165. BOOST_MATH_STD_USING
  166. if(x < 0)
  167. {
  168. // better have integer v:
  169. if(floor(v) == v)
  170. {
  171. T r = cyl_bessel_i_imp(v, T(-x), pol);
  172. if(iround(v, pol) & 1)
  173. r = -r;
  174. return r;
  175. }
  176. else
  177. return policies::raise_domain_error<T>(
  178. "boost::math::cyl_bessel_i<%1%>(%1%,%1%)",
  179. "Got x = %1%, but we need x >= 0", x, pol);
  180. }
  181. if(x == 0)
  182. {
  183. return (v == 0) ? static_cast<T>(1) : static_cast<T>(0);
  184. }
  185. if(v == 0.5f)
  186. {
  187. // common special case, note try and avoid overflow in exp(x):
  188. if(x >= tools::log_max_value<T>())
  189. {
  190. T e = exp(x / 2);
  191. return e * (e / sqrt(2 * x * constants::pi<T>()));
  192. }
  193. return sqrt(2 / (x * constants::pi<T>())) * sinh(x);
  194. }
  195. if((policies::digits<T, Policy>() <= 113) && (std::numeric_limits<T>::digits <= 113) && (std::numeric_limits<T>::radix == 2))
  196. {
  197. if(v == 0)
  198. {
  199. return bessel_i0(x);
  200. }
  201. if(v == 1)
  202. {
  203. return bessel_i1(x);
  204. }
  205. }
  206. if((v > 0) && (x / v < 0.25))
  207. return bessel_i_small_z_series(v, x, pol);
  208. T I, K;
  209. bessel_ik(v, x, &I, &K, need_i, pol);
  210. return I;
  211. }
  212. template <class T, class Policy>
  213. inline T cyl_bessel_k_imp(T v, T x, const bessel_no_int_tag& /* t */, const Policy& pol)
  214. {
  215. static const char* function = "boost::math::cyl_bessel_k<%1%>(%1%,%1%)";
  216. BOOST_MATH_STD_USING
  217. if(x < 0)
  218. {
  219. return policies::raise_domain_error<T>(
  220. function,
  221. "Got x = %1%, but we need x > 0", x, pol);
  222. }
  223. if(x == 0)
  224. {
  225. return (v == 0) ? policies::raise_overflow_error<T>(function, nullptr, pol)
  226. : policies::raise_domain_error<T>(
  227. function,
  228. "Got x = %1%, but we need x > 0", x, pol);
  229. }
  230. T I, K;
  231. bessel_ik(v, x, &I, &K, need_k, pol);
  232. return K;
  233. }
  234. template <class T, class Policy>
  235. inline T cyl_bessel_k_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol)
  236. {
  237. BOOST_MATH_STD_USING
  238. if((floor(v) == v))
  239. {
  240. return bessel_kn(itrunc(v), x, pol);
  241. }
  242. return cyl_bessel_k_imp(v, x, bessel_no_int_tag(), pol);
  243. }
  244. template <class T, class Policy>
  245. inline T cyl_bessel_k_imp(int v, T x, const bessel_int_tag&, const Policy& pol)
  246. {
  247. return bessel_kn(v, x, pol);
  248. }
  249. template <class T, class Policy>
  250. inline T cyl_neumann_imp(T v, T x, const bessel_no_int_tag&, const Policy& pol)
  251. {
  252. static const char* function = "boost::math::cyl_neumann<%1%>(%1%,%1%)";
  253. BOOST_MATH_INSTRUMENT_VARIABLE(v);
  254. BOOST_MATH_INSTRUMENT_VARIABLE(x);
  255. if(x <= 0)
  256. {
  257. return (v == 0) && (x == 0) ?
  258. policies::raise_overflow_error<T>(function, nullptr, pol)
  259. : policies::raise_domain_error<T>(
  260. function,
  261. "Got x = %1%, but result is complex for x <= 0", x, pol);
  262. }
  263. T j, y;
  264. bessel_jy(v, x, &j, &y, need_y, pol);
  265. //
  266. // Post evaluation check for internal overflow during evaluation,
  267. // can occur when x is small and v is large, in which case the result
  268. // is -INF:
  269. //
  270. if(!(boost::math::isfinite)(y))
  271. return -policies::raise_overflow_error<T>(function, nullptr, pol);
  272. return y;
  273. }
  274. template <class T, class Policy>
  275. inline T cyl_neumann_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol)
  276. {
  277. BOOST_MATH_STD_USING
  278. BOOST_MATH_INSTRUMENT_VARIABLE(v);
  279. BOOST_MATH_INSTRUMENT_VARIABLE(x);
  280. if(floor(v) == v)
  281. {
  282. T r = bessel_yn(itrunc(v, pol), x, pol);
  283. BOOST_MATH_INSTRUMENT_VARIABLE(r);
  284. return r;
  285. }
  286. T r = cyl_neumann_imp<T>(v, x, bessel_no_int_tag(), pol);
  287. BOOST_MATH_INSTRUMENT_VARIABLE(r);
  288. return r;
  289. }
  290. template <class T, class Policy>
  291. inline T cyl_neumann_imp(int v, T x, const bessel_int_tag&, const Policy& pol)
  292. {
  293. return bessel_yn(v, x, pol);
  294. }
  295. template <class T, class Policy>
  296. inline T sph_neumann_imp(unsigned v, T x, const Policy& pol)
  297. {
  298. BOOST_MATH_STD_USING // ADL of std names
  299. static const char* function = "boost::math::sph_neumann<%1%>(%1%,%1%)";
  300. //
  301. // Nothing much to do here but check for errors, and
  302. // evaluate the function's definition directly:
  303. //
  304. if(x < 0)
  305. return policies::raise_domain_error<T>(
  306. function,
  307. "Got x = %1%, but function requires x > 0.", x, pol);
  308. if(x < 2 * tools::min_value<T>())
  309. return -policies::raise_overflow_error<T>(function, nullptr, pol);
  310. T result = cyl_neumann_imp(T(T(v)+0.5f), x, bessel_no_int_tag(), pol);
  311. T tx = sqrt(constants::pi<T>() / (2 * x));
  312. if((tx > 1) && (tools::max_value<T>() / tx < result))
  313. return -policies::raise_overflow_error<T>(function, nullptr, pol);
  314. return result * tx;
  315. }
  316. template <class T, class Policy>
  317. inline T cyl_bessel_j_zero_imp(T v, int m, const Policy& pol)
  318. {
  319. BOOST_MATH_STD_USING // ADL of std names, needed for floor.
  320. static const char* function = "boost::math::cyl_bessel_j_zero<%1%>(%1%, int)";
  321. const T half_epsilon(boost::math::tools::epsilon<T>() / 2U);
  322. // Handle non-finite order.
  323. if (!(boost::math::isfinite)(v) )
  324. {
  325. return policies::raise_domain_error<T>(function, "Order argument is %1%, but must be finite >= 0 !", v, pol);
  326. }
  327. // Handle negative rank.
  328. if(m < 0)
  329. {
  330. // Zeros of Jv(x) with negative rank are not defined and requesting one raises a domain error.
  331. return policies::raise_domain_error<T>(function, "Requested the %1%'th zero, but the rank must be positive !", static_cast<T>(m), pol);
  332. }
  333. // Get the absolute value of the order.
  334. const bool order_is_negative = (v < 0);
  335. const T vv((!order_is_negative) ? v : T(-v));
  336. // Check if the order is very close to zero or very close to an integer.
  337. const bool order_is_zero = (vv < half_epsilon);
  338. const bool order_is_integer = ((vv - floor(vv)) < half_epsilon);
  339. if(m == 0)
  340. {
  341. if(order_is_zero)
  342. {
  343. // The zero'th zero of J0(x) is not defined and requesting it raises a domain error.
  344. return policies::raise_domain_error<T>(function, "Requested the %1%'th zero of J0, but the rank must be > 0 !", static_cast<T>(m), pol);
  345. }
  346. // The zero'th zero of Jv(x) for v < 0 is not defined
  347. // unless the order is a negative integer.
  348. if(order_is_negative && (!order_is_integer))
  349. {
  350. // For non-integer, negative order, requesting the zero'th zero raises a domain error.
  351. return policies::raise_domain_error<T>(function, "Requested the %1%'th zero of Jv for negative, non-integer order, but the rank must be > 0 !", static_cast<T>(m), pol);
  352. }
  353. // The zero'th zero does exist and its value is zero.
  354. return T(0);
  355. }
  356. // Set up the initial guess for the upcoming root-finding.
  357. // If the order is a negative integer, then use the corresponding
  358. // positive integer for the order.
  359. const T guess_root = boost::math::detail::bessel_zero::cyl_bessel_j_zero_detail::initial_guess<T, Policy>((order_is_integer ? vv : v), m, pol);
  360. // Select the maximum allowed iterations from the policy.
  361. std::uintmax_t number_of_iterations = policies::get_max_root_iterations<Policy>();
  362. const T delta_lo = ((guess_root > 0.2F) ? T(0.2) : T(guess_root / 2U));
  363. // Perform the root-finding using Newton-Raphson iteration from Boost.Math.
  364. const T jvm =
  365. boost::math::tools::newton_raphson_iterate(
  366. boost::math::detail::bessel_zero::cyl_bessel_j_zero_detail::function_object_jv_and_jv_prime<T, Policy>((order_is_integer ? vv : v), order_is_zero, pol),
  367. guess_root,
  368. T(guess_root - delta_lo),
  369. T(guess_root + 0.2F),
  370. policies::digits<T, Policy>(),
  371. number_of_iterations);
  372. if(number_of_iterations >= policies::get_max_root_iterations<Policy>())
  373. {
  374. return policies::raise_evaluation_error<T>(function, "Unable to locate root in a reasonable time:"
  375. " Current best guess is %1%", jvm, Policy());
  376. }
  377. return jvm;
  378. }
  379. template <class T, class Policy>
  380. inline T cyl_neumann_zero_imp(T v, int m, const Policy& pol)
  381. {
  382. BOOST_MATH_STD_USING // ADL of std names, needed for floor.
  383. static const char* function = "boost::math::cyl_neumann_zero<%1%>(%1%, int)";
  384. // Handle non-finite order.
  385. if (!(boost::math::isfinite)(v) )
  386. {
  387. return policies::raise_domain_error<T>(function, "Order argument is %1%, but must be finite >= 0 !", v, pol);
  388. }
  389. // Handle negative rank.
  390. if(m < 0)
  391. {
  392. return policies::raise_domain_error<T>(function, "Requested the %1%'th zero, but the rank must be positive !", static_cast<T>(m), pol);
  393. }
  394. const T half_epsilon(boost::math::tools::epsilon<T>() / 2U);
  395. // Get the absolute value of the order.
  396. const bool order_is_negative = (v < 0);
  397. const T vv((!order_is_negative) ? v : T(-v));
  398. const bool order_is_integer = ((vv - floor(vv)) < half_epsilon);
  399. // For negative integers, use reflection to positive integer order.
  400. if(order_is_negative && order_is_integer)
  401. return boost::math::detail::cyl_neumann_zero_imp(vv, m, pol);
  402. // Check if the order is very close to a negative half-integer.
  403. const T delta_half_integer(vv - (floor(vv) + 0.5F));
  404. const bool order_is_negative_half_integer =
  405. (order_is_negative && ((delta_half_integer > -half_epsilon) && (delta_half_integer < +half_epsilon)));
  406. // The zero'th zero of Yv(x) for v < 0 is not defined
  407. // unless the order is a negative integer.
  408. if((m == 0) && (!order_is_negative_half_integer))
  409. {
  410. // For non-integer, negative order, requesting the zero'th zero raises a domain error.
  411. return policies::raise_domain_error<T>(function, "Requested the %1%'th zero of Yv for negative, non-half-integer order, but the rank must be > 0 !", static_cast<T>(m), pol);
  412. }
  413. // For negative half-integers, use the corresponding
  414. // spherical Bessel function of positive half-integer order.
  415. if(order_is_negative_half_integer)
  416. return boost::math::detail::cyl_bessel_j_zero_imp(vv, m, pol);
  417. // Set up the initial guess for the upcoming root-finding.
  418. // If the order is a negative integer, then use the corresponding
  419. // positive integer for the order.
  420. const T guess_root = boost::math::detail::bessel_zero::cyl_neumann_zero_detail::initial_guess<T, Policy>(v, m, pol);
  421. // Select the maximum allowed iterations from the policy.
  422. std::uintmax_t number_of_iterations = policies::get_max_root_iterations<Policy>();
  423. const T delta_lo = ((guess_root > 0.2F) ? T(0.2) : T(guess_root / 2U));
  424. // Perform the root-finding using Newton-Raphson iteration from Boost.Math.
  425. const T yvm =
  426. boost::math::tools::newton_raphson_iterate(
  427. boost::math::detail::bessel_zero::cyl_neumann_zero_detail::function_object_yv_and_yv_prime<T, Policy>(v, pol),
  428. guess_root,
  429. T(guess_root - delta_lo),
  430. T(guess_root + 0.2F),
  431. policies::digits<T, Policy>(),
  432. number_of_iterations);
  433. if(number_of_iterations >= policies::get_max_root_iterations<Policy>())
  434. {
  435. return policies::raise_evaluation_error<T>(function, "Unable to locate root in a reasonable time:"
  436. " Current best guess is %1%", yvm, Policy());
  437. }
  438. return yvm;
  439. }
  440. } // namespace detail
  441. template <class T1, class T2, class Policy>
  442. inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_j(T1 v, T2 x, const Policy& /* pol */)
  443. {
  444. BOOST_FPU_EXCEPTION_GUARD
  445. typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type;
  446. typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag tag_type;
  447. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  448. typedef typename policies::normalise<
  449. Policy,
  450. policies::promote_float<false>,
  451. policies::promote_double<false>,
  452. policies::discrete_quantile<>,
  453. policies::assert_undefined<> >::type forwarding_policy;
  454. return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_j_imp<value_type>(v, static_cast<value_type>(x), tag_type(), forwarding_policy()), "boost::math::cyl_bessel_j<%1%>(%1%,%1%)");
  455. }
  456. template <class T1, class T2>
  457. inline typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_j(T1 v, T2 x)
  458. {
  459. return cyl_bessel_j(v, x, policies::policy<>());
  460. }
  461. template <class T, class Policy>
  462. inline typename detail::bessel_traits<T, T, Policy>::result_type sph_bessel(unsigned v, T x, const Policy& /* pol */)
  463. {
  464. BOOST_FPU_EXCEPTION_GUARD
  465. typedef typename detail::bessel_traits<T, T, Policy>::result_type result_type;
  466. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  467. typedef typename policies::normalise<
  468. Policy,
  469. policies::promote_float<false>,
  470. policies::promote_double<false>,
  471. policies::discrete_quantile<>,
  472. policies::assert_undefined<> >::type forwarding_policy;
  473. return policies::checked_narrowing_cast<result_type, Policy>(detail::sph_bessel_j_imp<value_type>(v, static_cast<value_type>(x), forwarding_policy()), "boost::math::sph_bessel<%1%>(%1%,%1%)");
  474. }
  475. template <class T>
  476. inline typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_bessel(unsigned v, T x)
  477. {
  478. return sph_bessel(v, x, policies::policy<>());
  479. }
  480. template <class T1, class T2, class Policy>
  481. inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_i(T1 v, T2 x, const Policy& /* pol */)
  482. {
  483. BOOST_FPU_EXCEPTION_GUARD
  484. typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type;
  485. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  486. typedef typename policies::normalise<
  487. Policy,
  488. policies::promote_float<false>,
  489. policies::promote_double<false>,
  490. policies::discrete_quantile<>,
  491. policies::assert_undefined<> >::type forwarding_policy;
  492. return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_i_imp<value_type>(static_cast<value_type>(v), static_cast<value_type>(x), forwarding_policy()), "boost::math::cyl_bessel_i<%1%>(%1%,%1%)");
  493. }
  494. template <class T1, class T2>
  495. inline typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_i(T1 v, T2 x)
  496. {
  497. return cyl_bessel_i(v, x, policies::policy<>());
  498. }
  499. template <class T1, class T2, class Policy>
  500. inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_k(T1 v, T2 x, const Policy& /* pol */)
  501. {
  502. BOOST_FPU_EXCEPTION_GUARD
  503. typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type;
  504. typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag128 tag_type;
  505. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  506. typedef typename policies::normalise<
  507. Policy,
  508. policies::promote_float<false>,
  509. policies::promote_double<false>,
  510. policies::discrete_quantile<>,
  511. policies::assert_undefined<> >::type forwarding_policy;
  512. return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_k_imp<value_type>(v, static_cast<value_type>(x), tag_type(), forwarding_policy()), "boost::math::cyl_bessel_k<%1%>(%1%,%1%)");
  513. }
  514. template <class T1, class T2>
  515. inline typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_k(T1 v, T2 x)
  516. {
  517. return cyl_bessel_k(v, x, policies::policy<>());
  518. }
  519. template <class T1, class T2, class Policy>
  520. inline typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_neumann(T1 v, T2 x, const Policy& /* pol */)
  521. {
  522. BOOST_FPU_EXCEPTION_GUARD
  523. typedef typename detail::bessel_traits<T1, T2, Policy>::result_type result_type;
  524. typedef typename detail::bessel_traits<T1, T2, Policy>::optimisation_tag tag_type;
  525. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  526. typedef typename policies::normalise<
  527. Policy,
  528. policies::promote_float<false>,
  529. policies::promote_double<false>,
  530. policies::discrete_quantile<>,
  531. policies::assert_undefined<> >::type forwarding_policy;
  532. return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_neumann_imp<value_type>(v, static_cast<value_type>(x), tag_type(), forwarding_policy()), "boost::math::cyl_neumann<%1%>(%1%,%1%)");
  533. }
  534. template <class T1, class T2>
  535. inline typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_neumann(T1 v, T2 x)
  536. {
  537. return cyl_neumann(v, x, policies::policy<>());
  538. }
  539. template <class T, class Policy>
  540. inline typename detail::bessel_traits<T, T, Policy>::result_type sph_neumann(unsigned v, T x, const Policy& /* pol */)
  541. {
  542. BOOST_FPU_EXCEPTION_GUARD
  543. typedef typename detail::bessel_traits<T, T, Policy>::result_type result_type;
  544. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  545. typedef typename policies::normalise<
  546. Policy,
  547. policies::promote_float<false>,
  548. policies::promote_double<false>,
  549. policies::discrete_quantile<>,
  550. policies::assert_undefined<> >::type forwarding_policy;
  551. return policies::checked_narrowing_cast<result_type, Policy>(detail::sph_neumann_imp<value_type>(v, static_cast<value_type>(x), forwarding_policy()), "boost::math::sph_neumann<%1%>(%1%,%1%)");
  552. }
  553. template <class T>
  554. inline typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_neumann(unsigned v, T x)
  555. {
  556. return sph_neumann(v, x, policies::policy<>());
  557. }
  558. template <class T, class Policy>
  559. inline typename detail::bessel_traits<T, T, Policy>::result_type cyl_bessel_j_zero(T v, int m, const Policy& /* pol */)
  560. {
  561. BOOST_FPU_EXCEPTION_GUARD
  562. typedef typename detail::bessel_traits<T, T, Policy>::result_type result_type;
  563. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  564. typedef typename policies::normalise<
  565. Policy,
  566. policies::promote_float<false>,
  567. policies::promote_double<false>,
  568. policies::discrete_quantile<>,
  569. policies::assert_undefined<> >::type forwarding_policy;
  570. static_assert( false == std::numeric_limits<T>::is_specialized
  571. || ( true == std::numeric_limits<T>::is_specialized
  572. && false == std::numeric_limits<T>::is_integer),
  573. "Order must be a floating-point type.");
  574. return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_bessel_j_zero_imp<value_type>(v, m, forwarding_policy()), "boost::math::cyl_bessel_j_zero<%1%>(%1%,%1%)");
  575. }
  576. template <class T>
  577. inline typename detail::bessel_traits<T, T, policies::policy<> >::result_type cyl_bessel_j_zero(T v, int m)
  578. {
  579. static_assert( false == std::numeric_limits<T>::is_specialized
  580. || ( true == std::numeric_limits<T>::is_specialized
  581. && false == std::numeric_limits<T>::is_integer),
  582. "Order must be a floating-point type.");
  583. return cyl_bessel_j_zero<T, policies::policy<> >(v, m, policies::policy<>());
  584. }
  585. template <class T, class OutputIterator, class Policy>
  586. inline OutputIterator cyl_bessel_j_zero(T v,
  587. int start_index,
  588. unsigned number_of_zeros,
  589. OutputIterator out_it,
  590. const Policy& pol)
  591. {
  592. static_assert( false == std::numeric_limits<T>::is_specialized
  593. || ( true == std::numeric_limits<T>::is_specialized
  594. && false == std::numeric_limits<T>::is_integer),
  595. "Order must be a floating-point type.");
  596. for(int i = 0; i < static_cast<int>(number_of_zeros); ++i)
  597. {
  598. *out_it = boost::math::cyl_bessel_j_zero(v, start_index + i, pol);
  599. ++out_it;
  600. }
  601. return out_it;
  602. }
  603. template <class T, class OutputIterator>
  604. inline OutputIterator cyl_bessel_j_zero(T v,
  605. int start_index,
  606. unsigned number_of_zeros,
  607. OutputIterator out_it)
  608. {
  609. return cyl_bessel_j_zero(v, start_index, number_of_zeros, out_it, policies::policy<>());
  610. }
  611. template <class T, class Policy>
  612. inline typename detail::bessel_traits<T, T, Policy>::result_type cyl_neumann_zero(T v, int m, const Policy& /* pol */)
  613. {
  614. BOOST_FPU_EXCEPTION_GUARD
  615. typedef typename detail::bessel_traits<T, T, Policy>::result_type result_type;
  616. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  617. typedef typename policies::normalise<
  618. Policy,
  619. policies::promote_float<false>,
  620. policies::promote_double<false>,
  621. policies::discrete_quantile<>,
  622. policies::assert_undefined<> >::type forwarding_policy;
  623. static_assert( false == std::numeric_limits<T>::is_specialized
  624. || ( true == std::numeric_limits<T>::is_specialized
  625. && false == std::numeric_limits<T>::is_integer),
  626. "Order must be a floating-point type.");
  627. return policies::checked_narrowing_cast<result_type, Policy>(detail::cyl_neumann_zero_imp<value_type>(v, m, forwarding_policy()), "boost::math::cyl_neumann_zero<%1%>(%1%,%1%)");
  628. }
  629. template <class T>
  630. inline typename detail::bessel_traits<T, T, policies::policy<> >::result_type cyl_neumann_zero(T v, int m)
  631. {
  632. static_assert( false == std::numeric_limits<T>::is_specialized
  633. || ( true == std::numeric_limits<T>::is_specialized
  634. && false == std::numeric_limits<T>::is_integer),
  635. "Order must be a floating-point type.");
  636. return cyl_neumann_zero<T, policies::policy<> >(v, m, policies::policy<>());
  637. }
  638. template <class T, class OutputIterator, class Policy>
  639. inline OutputIterator cyl_neumann_zero(T v,
  640. int start_index,
  641. unsigned number_of_zeros,
  642. OutputIterator out_it,
  643. const Policy& pol)
  644. {
  645. static_assert( false == std::numeric_limits<T>::is_specialized
  646. || ( true == std::numeric_limits<T>::is_specialized
  647. && false == std::numeric_limits<T>::is_integer),
  648. "Order must be a floating-point type.");
  649. for(int i = 0; i < static_cast<int>(number_of_zeros); ++i)
  650. {
  651. *out_it = boost::math::cyl_neumann_zero(v, start_index + i, pol);
  652. ++out_it;
  653. }
  654. return out_it;
  655. }
  656. template <class T, class OutputIterator>
  657. inline OutputIterator cyl_neumann_zero(T v,
  658. int start_index,
  659. unsigned number_of_zeros,
  660. OutputIterator out_it)
  661. {
  662. return cyl_neumann_zero(v, start_index, number_of_zeros, out_it, policies::policy<>());
  663. }
  664. } // namespace math
  665. } // namespace boost
  666. #ifdef _MSC_VER
  667. # pragma warning(pop)
  668. #endif
  669. #endif // BOOST_MATH_BESSEL_HPP