File indexing completed on 2025-01-18 09:40:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef _BOOST_BERNOULLI_B2N_2013_05_30_HPP_
0012 #define _BOOST_BERNOULLI_B2N_2013_05_30_HPP_
0013
0014 #include <boost/math/special_functions/math_fwd.hpp>
0015 #include <boost/math/special_functions/detail/unchecked_bernoulli.hpp>
0016 #include <boost/math/special_functions/detail/bernoulli_details.hpp>
0017
0018 namespace boost { namespace math {
0019
0020 namespace detail {
0021
0022 template <class T, class OutputIterator, class Policy, int N>
0023 OutputIterator bernoulli_number_imp(OutputIterator out, std::size_t start, std::size_t n, const Policy& pol, const std::integral_constant<int, N>& tag)
0024 {
0025 for(std::size_t i = start; (i <= max_bernoulli_b2n<T>::value) && (i < start + n); ++i)
0026 {
0027 *out = unchecked_bernoulli_imp<T>(i, tag);
0028 ++out;
0029 }
0030
0031 for(std::size_t i = (std::max)(static_cast<std::size_t>(max_bernoulli_b2n<T>::value + 1), start); i < start + n; ++i)
0032 {
0033
0034 *out = (i & 1 ? 1 : -1) * policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(n)", nullptr, T(i), pol);
0035 ++out;
0036 }
0037 return out;
0038 }
0039
0040 template <class T, class OutputIterator, class Policy>
0041 OutputIterator bernoulli_number_imp(OutputIterator out, std::size_t start, std::size_t n, const Policy& pol, const std::integral_constant<int, 0>& tag)
0042 {
0043 for(std::size_t i = start; (i <= max_bernoulli_b2n<T>::value) && (i < start + n); ++i)
0044 {
0045 *out = unchecked_bernoulli_imp<T>(i, tag);
0046 ++out;
0047 }
0048
0049
0050
0051 if(start + n <= max_bernoulli_b2n<T>::value)
0052 {
0053 return out;
0054 }
0055
0056 return get_bernoulli_numbers_cache<T, Policy>().copy_bernoulli_numbers(out, start, n, pol);
0057 }
0058
0059 }
0060
0061 template <class T, class Policy>
0062 inline T bernoulli_b2n(const int i, const Policy &pol)
0063 {
0064 using tag_type = std::integral_constant<int, detail::bernoulli_imp_variant<T>::value>;
0065 if(i < 0)
0066 {
0067 return policies::raise_domain_error<T>("boost::math::bernoulli_b2n<%1%>", "Index should be >= 0 but got %1%", T(i), pol);
0068 }
0069
0070 T result {};
0071 boost::math::detail::bernoulli_number_imp<T>(&result, static_cast<std::size_t>(i), 1u, pol, tag_type());
0072 return result;
0073 }
0074
0075 template <class T>
0076 inline T bernoulli_b2n(const int i)
0077 {
0078 return boost::math::bernoulli_b2n<T>(i, policies::policy<>());
0079 }
0080
0081 template <class T, class OutputIterator, class Policy>
0082 inline OutputIterator bernoulli_b2n(const int start_index,
0083 const unsigned number_of_bernoullis_b2n,
0084 OutputIterator out_it,
0085 const Policy& pol)
0086 {
0087 using tag_type = std::integral_constant<int, detail::bernoulli_imp_variant<T>::value>;
0088 if(start_index < 0)
0089 {
0090 *out_it = policies::raise_domain_error<T>("boost::math::bernoulli_b2n<%1%>", "Index should be >= 0 but got %1%", T(start_index), pol);
0091 return ++out_it;
0092 }
0093
0094 return boost::math::detail::bernoulli_number_imp<T>(out_it, start_index, number_of_bernoullis_b2n, pol, tag_type());
0095 }
0096
0097 template <class T, class OutputIterator>
0098 inline OutputIterator bernoulli_b2n(const int start_index,
0099 const unsigned number_of_bernoullis_b2n,
0100 OutputIterator out_it)
0101 {
0102 return boost::math::bernoulli_b2n<T, OutputIterator>(start_index, number_of_bernoullis_b2n, out_it, policies::policy<>());
0103 }
0104
0105 template <class T, class Policy>
0106 inline T tangent_t2n(const int i, const Policy &pol)
0107 {
0108 if(i < 0)
0109 {
0110 return policies::raise_domain_error<T>("boost::math::tangent_t2n<%1%>", "Index should be >= 0 but got %1%", T(i), pol);
0111 }
0112
0113 T result {};
0114 boost::math::detail::get_bernoulli_numbers_cache<T, Policy>().copy_tangent_numbers(&result, i, 1, pol);
0115 return result;
0116 }
0117
0118 template <class T>
0119 inline T tangent_t2n(const int i)
0120 {
0121 return boost::math::tangent_t2n<T>(i, policies::policy<>());
0122 }
0123
0124 template <class T, class OutputIterator, class Policy>
0125 inline OutputIterator tangent_t2n(const int start_index,
0126 const unsigned number_of_tangent_t2n,
0127 OutputIterator out_it,
0128 const Policy& pol)
0129 {
0130 if(start_index < 0)
0131 {
0132 *out_it = policies::raise_domain_error<T>("boost::math::tangent_t2n<%1%>", "Index should be >= 0 but got %1%", T(start_index), pol);
0133 return ++out_it;
0134 }
0135
0136 return boost::math::detail::get_bernoulli_numbers_cache<T, Policy>().copy_tangent_numbers(out_it, start_index, number_of_tangent_t2n, pol);
0137 }
0138
0139 template <class T, class OutputIterator>
0140 inline OutputIterator tangent_t2n(const int start_index,
0141 const unsigned number_of_tangent_t2n,
0142 OutputIterator out_it)
0143 {
0144 return boost::math::tangent_t2n<T, OutputIterator>(start_index, number_of_tangent_t2n, out_it, policies::policy<>());
0145 }
0146
0147 } }
0148
0149 #endif