Debian Codegraph @

third-party/boost-math/include/boost/math/special_functions/detail/bessel_derivatives_linear.hpp

raw
1 // Copyright (c) 2013 Anton Bikineev
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
6 //
7 // This is a partial header, do not include on it's own!!!
8 //
9 // Linear combination for bessel derivatives are defined here
10 #ifndef BOOST_MATH_SF_DETAIL_BESSEL_DERIVATIVES_LINEAR_HPP
11 #define BOOST_MATH_SF_DETAIL_BESSEL_DERIVATIVES_LINEAR_HPP
12 #include <iostream>
13 #ifdef _MSC_VER
14 #pragma once
15 #endif
16
17 namespace boost{ namespace math{ namespace detail{
18
19 template <class T, class Tag, class Policy>
20 inline T bessel_j_derivative_linear(T v, T x, Tag tag, Policy pol)
21 {
22 return (boost::math::detail::cyl_bessel_j_imp<T>(v-1, x, tag, pol) - boost::math::detail::cyl_bessel_j_imp<T>(v+1, x, tag, pol)) / 2;
23 }
24
25 template <class T, class Policy>
26 inline T bessel_j_derivative_linear(T v, T x, const bessel_int_tag& tag, Policy pol)
27 {
28 return (boost::math::detail::cyl_bessel_j_imp<T>(itrunc(v-1), x, tag, pol) - boost::math::detail::cyl_bessel_j_imp<T>(itrunc(v+1), x, tag, pol)) / 2;
29 }
30
31 template <class T, class Policy>
32 inline T sph_bessel_j_derivative_linear(unsigned v, T x, Policy pol)
33 {
34 return (v / x) * boost::math::detail::sph_bessel_j_imp<T>(v, x, pol) - boost::math::detail::sph_bessel_j_imp<T>(v+1, x, pol);
35 }
36
37 template <class T, class Policy>
38 inline T bessel_i_derivative_linear(T v, T x, Policy pol)
39 {
40 T result = boost::math::detail::cyl_bessel_i_imp<T>(v - 1, x, pol);
41 if(result >= tools::max_value<T>())
42 return result; // result is infinite
43 // Both experimentally, and based on https://www.wolframalpha.com/input?i=BesselI%5Bv%2C+x%5D%2FBesselI%5Bv%2B2%2C+x%5D
44 // I[v + 1, x] < I[v-1, x], so this can't overflow:
45 T result2 = boost::math::detail::cyl_bessel_i_imp<T>(v + 1, x, pol);
46
47 return result / 2 + result2 / 2;
48 }
49
50 template <class T, class Tag, class Policy>
51 inline T bessel_k_derivative_linear(T v, T x, Tag tag, Policy pol)
52 {
53 T result = boost::math::detail::cyl_bessel_k_imp<T>(v - 1, x, tag, pol);
54 if(result >= tools::max_value<T>())
55 return -result; // result is infinite
56 T result2 = boost::math::detail::cyl_bessel_k_imp<T>(v + 1, x, tag, pol);
57 if(result2 >= tools::max_value<T>() + result)
58 return -boost::math::policies::raise_overflow_error<T>("cyl_bessel_k_prime<%1>", 0, pol); // result is infinite
59 result /= -2;
60 result2 /= -2;
61 return result + result2;
62 }
63
64 template <class T, class Policy>
65 inline T bessel_k_derivative_linear(T v, T x, const bessel_int_tag& tag, Policy pol)
66 {
67 T result = boost::math::detail::cyl_bessel_k_imp<T>(itrunc(v - 1), x, tag, pol);
68 if (result >= tools::max_value<T>())
69 return -result; // result is infinite
70 T result2 = boost::math::detail::cyl_bessel_k_imp<T>(itrunc(v + 1), x, tag, pol);
71 if (result2 >= tools::max_value<T>() + result)
72 return -boost::math::policies::raise_overflow_error<T>("cyl_bessel_k_prime<%1>", 0, pol); // result is infinite
73 result /= -2;
74 result2 /= -2;
75 return result + result2;
76 }
77
78 template <class T, class Policy>
79 inline T bessel_k_derivative_linear(T v, T x, const bessel_maybe_int_tag&, Policy pol)
80 {
81 using std::floor;
82 if (floor(v) == v)
83 return bessel_k_derivative_linear(v, x, bessel_int_tag(), pol);
84 return bessel_k_derivative_linear(v, x, bessel_no_int_tag(), pol);
85 }
86
87 template <class T, class Tag, class Policy>
88 inline T bessel_y_derivative_linear(T v, T x, Tag tag, Policy pol)
89 {
90 return (boost::math::detail::cyl_neumann_imp<T>(v-1, x, tag, pol) - boost::math::detail::cyl_neumann_imp<T>(v+1, x, tag, pol)) / 2;
91 }
92
93 template <class T, class Policy>
94 inline T bessel_y_derivative_linear(T v, T x, const bessel_int_tag& tag, Policy pol)
95 {
96 return (boost::math::detail::cyl_neumann_imp<T>(itrunc(v-1), x, tag, pol) - boost::math::detail::cyl_neumann_imp<T>(itrunc(v+1), x, tag, pol)) / 2;
97 }
98
99 template <class T, class Policy>
100 inline T sph_neumann_derivative_linear(unsigned v, T x, Policy pol)
101 {
102 return (v / x) * boost::math::detail::sph_neumann_imp<T>(v, x, pol) - boost::math::detail::sph_neumann_imp<T>(v+1, x, pol);
103 }
104
105 }}} // namespaces
106
107 #endif // BOOST_MATH_SF_DETAIL_BESSEL_DERIVATIVES_LINEAR_HPP